@inkeep/agents-cli 0.51.0 → 0.53.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/agents-cli/package.js +6 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/dev.js +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/{pull-v3 → pull-v4}/component-parser.js +6 -12
- package/dist/commands/{pull-v3/utils → pull-v4}/component-registry.js +1 -1
- package/dist/commands/pull-v4/generators/agent-generator.js +258 -0
- package/dist/commands/pull-v4/generators/artifact-component-generator.js +69 -0
- package/dist/commands/pull-v4/generators/context-config-generator.js +264 -0
- package/dist/commands/pull-v4/generators/credential-generator.js +30 -0
- package/dist/commands/pull-v4/generators/data-component-generator.js +50 -0
- package/dist/commands/pull-v4/generators/environment-generator.js +123 -0
- package/dist/commands/pull-v4/generators/external-agent-generator.js +56 -0
- package/dist/commands/pull-v4/generators/function-tool-generator.js +48 -0
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js +91 -0
- package/dist/commands/pull-v4/generators/project-generator.js +125 -0
- package/dist/commands/{pull-v3/components → pull-v4/generators}/skill-generator.js +1 -1
- package/dist/commands/pull-v4/generators/status-component-generator.js +35 -0
- package/dist/commands/pull-v4/generators/sub-agent-generator.js +269 -0
- package/dist/commands/pull-v4/generators/trigger-generator.js +58 -0
- package/dist/commands/pull-v4/introspect/index.js +365 -0
- package/dist/commands/pull-v4/introspect/test-helpers.js +143 -0
- package/dist/commands/pull-v4/introspect-generator.js +706 -0
- package/dist/commands/pull-v4/module-merge.js +405 -0
- package/dist/commands/pull-v4/utils.js +235 -0
- package/dist/commands/push.js +1 -1
- package/dist/commands/update.js +2 -2
- package/dist/index.js +18 -44
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/array.js +18 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js +180 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/character.js +8 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/css.js +12 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/json.js +60 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/line.js +37 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js +31 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/word.js +118 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/index.js +11 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/patch/create.js +141 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/util/string.js +63 -0
- package/dist/utils/ci-environment.js +1 -1
- package/dist/utils/config.js +1 -1
- package/dist/utils/environment-loader.js +1 -1
- package/dist/utils/file-finder.js +1 -1
- package/dist/utils/mcp-runner.js +1 -1
- package/dist/utils/profile-config.js +1 -1
- package/dist/utils/profiles/profile-manager.js +1 -1
- package/dist/utils/project-directory.js +1 -1
- package/dist/utils/project-loader.js +1 -1
- package/dist/utils/version-check.js +6 -15
- package/package.json +5 -7
- package/dist/commands/pull-v3/component-updater.js +0 -768
- package/dist/commands/pull-v3/components/agent-generator.js +0 -255
- package/dist/commands/pull-v3/components/artifact-component-generator.js +0 -143
- package/dist/commands/pull-v3/components/context-config-generator.js +0 -190
- package/dist/commands/pull-v3/components/credential-generator.js +0 -89
- package/dist/commands/pull-v3/components/data-component-generator.js +0 -102
- package/dist/commands/pull-v3/components/environment-generator.js +0 -173
- package/dist/commands/pull-v3/components/external-agent-generator.js +0 -75
- package/dist/commands/pull-v3/components/function-tool-generator.js +0 -92
- package/dist/commands/pull-v3/components/mcp-tool-generator.js +0 -86
- package/dist/commands/pull-v3/components/project-generator.js +0 -157
- package/dist/commands/pull-v3/components/status-component-generator.js +0 -92
- package/dist/commands/pull-v3/components/sub-agent-generator.js +0 -295
- package/dist/commands/pull-v3/components/trigger-generator.js +0 -185
- package/dist/commands/pull-v3/index.js +0 -510
- package/dist/commands/pull-v3/introspect-generator.js +0 -286
- package/dist/commands/pull-v3/llm-content-merger.js +0 -192
- package/dist/commands/pull-v3/new-component-generator.js +0 -279
- package/dist/commands/pull-v3/project-comparator.js +0 -914
- package/dist/commands/pull-v3/project-index-generator.js +0 -32
- package/dist/commands/pull-v3/project-validator.js +0 -358
- package/dist/commands/pull-v3/targeted-typescript-placeholders.js +0 -173
- package/dist/commands/pull-v3/utils/component-tracker.js +0 -165
- package/dist/commands/pull-v3/utils/generator-utils.js +0 -146
- package/dist/commands/pull-v3/utils/model-provider-detector.js +0 -50
- package/dist/utils/url.js +0 -26
package/dist/commands/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LOCAL_REMOTE } from "../utils/profiles/types.js";
|
|
2
2
|
import "../utils/profiles/index.js";
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import chalk from "chalk";
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
6
|
|
|
7
7
|
//#region src/commands/config.ts
|
|
8
8
|
async function configGetCommand(key, options) {
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
2
|
import { dirname, join } from "node:path";
|
|
4
3
|
import * as p from "@clack/prompts";
|
|
5
4
|
import chalk from "chalk";
|
|
6
5
|
import fs from "fs-extra";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
7
|
import { fork } from "node:child_process";
|
|
8
8
|
import open from "open";
|
|
9
9
|
|
package/dist/commands/init.js
CHANGED
|
@@ -3,10 +3,10 @@ import { DEFAULT_PROFILES_CONFIG, LOCAL_REMOTE } from "../utils/profiles/types.j
|
|
|
3
3
|
import { ProfileManager } from "../utils/profiles/profile-manager.js";
|
|
4
4
|
import "../utils/profiles/index.js";
|
|
5
5
|
import { loginCommand } from "./login.js";
|
|
6
|
-
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
7
6
|
import { basename, dirname, join, resolve } from "node:path";
|
|
8
7
|
import * as p from "@clack/prompts";
|
|
9
8
|
import chalk from "chalk";
|
|
9
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
10
10
|
|
|
11
11
|
//#region src/commands/init.ts
|
|
12
12
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ComponentRegistry } from "./
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentRegistry } from "./component-registry.js";
|
|
2
|
+
import { createInMemoryProject } from "./utils.js";
|
|
3
3
|
import { extname, join, relative } from "node:path";
|
|
4
|
-
import { Node
|
|
4
|
+
import { Node } from "ts-morph";
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
5
6
|
|
|
6
|
-
//#region src/commands/pull-
|
|
7
|
+
//#region src/commands/pull-v4/component-parser.ts
|
|
7
8
|
/**
|
|
8
9
|
* Component Parser - Find all component definitions (exported and inline)
|
|
9
10
|
* Uses AST parsing to handle complex components including those with render attributes
|
|
@@ -58,14 +59,7 @@ function parseFileForComponents(filePath, projectRoot, debug = false) {
|
|
|
58
59
|
const relativePath = relative(projectRoot, filePath);
|
|
59
60
|
try {
|
|
60
61
|
const content = readFileSync(filePath, "utf8");
|
|
61
|
-
const sourceFile =
|
|
62
|
-
useInMemoryFileSystem: true,
|
|
63
|
-
compilerOptions: {
|
|
64
|
-
allowJs: true,
|
|
65
|
-
target: 99,
|
|
66
|
-
jsx: 1
|
|
67
|
-
}
|
|
68
|
-
}).createSourceFile("temp.ts", content);
|
|
62
|
+
const sourceFile = createInMemoryProject().createSourceFile("temp.ts", content);
|
|
69
63
|
const exportedVariableDeclarations = sourceFile.getVariableStatements().filter((statement) => statement.hasExportKeyword()).flatMap((statement) => statement.getDeclarationList().getDeclarations());
|
|
70
64
|
for (const declaration of exportedVariableDeclarations) {
|
|
71
65
|
const variableName = declaration.getName();
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { addObjectEntries, addReferenceGetterProperty, addStringProperty, collectTemplateVariableNames, createFactoryDefinition, createUniqueReferenceName, formatStringLiteral, formatTemplate, isPlainObject, toCamelCase } from "../utils.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { SyntaxKind } from "ts-morph";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/pull-v4/generators/agent-generator.ts
|
|
6
|
+
const SubAgentReferenceSchema = z.object({
|
|
7
|
+
name: z.string().nonempty(),
|
|
8
|
+
local: z.boolean().optional()
|
|
9
|
+
});
|
|
10
|
+
const AgentSchema = z.looseObject({
|
|
11
|
+
agentId: z.string().nonempty(),
|
|
12
|
+
name: z.string().nonempty(),
|
|
13
|
+
description: z.string().nullish(),
|
|
14
|
+
prompt: z.string().optional(),
|
|
15
|
+
models: z.looseObject({}).optional(),
|
|
16
|
+
defaultSubAgentId: z.string().nonempty(),
|
|
17
|
+
subAgents: z.union([z.array(z.string()), z.record(z.string(), z.unknown())]),
|
|
18
|
+
contextConfig: z.union([z.string(), z.looseObject({ id: z.string().optional() })]).optional(),
|
|
19
|
+
stopWhen: z.object({ transferCountIs: z.int().optional() }).optional(),
|
|
20
|
+
statusUpdates: z.strictObject({
|
|
21
|
+
numEvents: z.int().optional(),
|
|
22
|
+
timeInSeconds: z.int().optional(),
|
|
23
|
+
statusComponents: z.array(z.union([z.string(), z.looseObject({
|
|
24
|
+
id: z.string().optional(),
|
|
25
|
+
type: z.string(),
|
|
26
|
+
name: z.string().optional()
|
|
27
|
+
})])).optional(),
|
|
28
|
+
prompt: z.string().optional()
|
|
29
|
+
}).optional(),
|
|
30
|
+
credentials: z.array(z.union([z.string(), z.strictObject({ id: z.string() })])).optional(),
|
|
31
|
+
triggers: z.union([z.array(z.string()), z.record(z.string(), z.unknown())]).optional(),
|
|
32
|
+
agentVariableName: z.string().nonempty().optional(),
|
|
33
|
+
subAgentReferences: z.record(z.string(), SubAgentReferenceSchema).optional(),
|
|
34
|
+
contextConfigReference: SubAgentReferenceSchema.optional(),
|
|
35
|
+
contextConfigHeadersReference: SubAgentReferenceSchema.optional()
|
|
36
|
+
});
|
|
37
|
+
function generateAgentDefinition(data) {
|
|
38
|
+
const result = AgentSchema.safeParse(data);
|
|
39
|
+
if (!result.success) throw new Error(`Validation failed for agent:\n${z.prettifyError(result.error)}`);
|
|
40
|
+
const parsed = result.data;
|
|
41
|
+
const subAgentIds = new Set(extractIds(parsed.subAgents));
|
|
42
|
+
subAgentIds.add(parsed.defaultSubAgentId);
|
|
43
|
+
const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);
|
|
44
|
+
const { sourceFile, configObject } = createFactoryDefinition({
|
|
45
|
+
importName: "agent",
|
|
46
|
+
variableName: agentVarName
|
|
47
|
+
});
|
|
48
|
+
const reservedReferenceNames = new Set([agentVarName]);
|
|
49
|
+
const { referenceNames: subAgentReferenceNames, importNames: subAgentImportNames } = createSubAgentReferenceMaps(subAgentIds, reservedReferenceNames, "SubAgent", parsed.subAgentReferences);
|
|
50
|
+
addSubAgentImports(sourceFile, subAgentReferenceNames, subAgentImportNames);
|
|
51
|
+
const contextConfigId = extractContextConfigId(parsed.contextConfig);
|
|
52
|
+
let contextConfigReferenceName;
|
|
53
|
+
let contextHeadersReferenceName;
|
|
54
|
+
const hasHeadersTemplateVariables = collectTemplateVariableNamesFromFields([parsed.prompt, parsed.statusUpdates?.prompt]).some((variableName) => variableName.startsWith("headers."));
|
|
55
|
+
if (contextConfigId) {
|
|
56
|
+
const contextConfigImportName = parsed.contextConfigReference?.name ?? toCamelCase(contextConfigId);
|
|
57
|
+
contextConfigReferenceName = createUniqueReferenceName(contextConfigImportName, reservedReferenceNames, "ContextConfig");
|
|
58
|
+
const contextHeadersImportName = parsed.contextConfigHeadersReference?.name ?? `${toCamelCase(contextConfigId)}Headers`;
|
|
59
|
+
if (hasHeadersTemplateVariables) contextHeadersReferenceName = createUniqueReferenceName(contextHeadersImportName, reservedReferenceNames, "Headers");
|
|
60
|
+
const namedImports = [];
|
|
61
|
+
if (parsed.contextConfigReference?.local !== true) namedImports.push(contextConfigImportName === contextConfigReferenceName ? contextConfigImportName : {
|
|
62
|
+
name: contextConfigImportName,
|
|
63
|
+
alias: contextConfigReferenceName
|
|
64
|
+
});
|
|
65
|
+
if (hasHeadersTemplateVariables && contextHeadersReferenceName && parsed.contextConfigHeadersReference?.local !== true) namedImports.push(contextHeadersImportName === contextHeadersReferenceName ? contextHeadersImportName : {
|
|
66
|
+
name: contextHeadersImportName,
|
|
67
|
+
alias: contextHeadersReferenceName
|
|
68
|
+
});
|
|
69
|
+
if (namedImports.length > 0) sourceFile.addImportDeclaration({
|
|
70
|
+
namedImports,
|
|
71
|
+
moduleSpecifier: `../context-configs/${contextConfigId}`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const triggerReferenceNames = createReferenceNameMap(parsed.triggers ? extractIds(parsed.triggers) : [], reservedReferenceNames, "Trigger");
|
|
75
|
+
addTriggerImports(sourceFile, triggerReferenceNames);
|
|
76
|
+
const statusComponentReferenceNames = createReferenceNameMap(extractStatusComponentIds(parsed.statusUpdates), reservedReferenceNames, "StatusComponent");
|
|
77
|
+
addStatusComponentImports(sourceFile, statusComponentReferenceNames);
|
|
78
|
+
writeAgentConfig(configObject, parsed, {
|
|
79
|
+
subAgents: subAgentReferenceNames,
|
|
80
|
+
contextConfig: contextConfigReferenceName,
|
|
81
|
+
contextHeaders: contextHeadersReferenceName,
|
|
82
|
+
triggers: triggerReferenceNames,
|
|
83
|
+
statusComponents: statusComponentReferenceNames
|
|
84
|
+
});
|
|
85
|
+
return sourceFile;
|
|
86
|
+
}
|
|
87
|
+
function writeAgentConfig(configObject, data, referenceNames) {
|
|
88
|
+
addStringProperty(configObject, "id", data.agentId);
|
|
89
|
+
addStringProperty(configObject, "name", data.name);
|
|
90
|
+
if (data.description != null) addStringProperty(configObject, "description", data.description);
|
|
91
|
+
if (data.prompt !== void 0) {
|
|
92
|
+
const template = formatTemplate(data.prompt, {
|
|
93
|
+
contextReference: referenceNames.contextConfig,
|
|
94
|
+
headersReference: referenceNames.contextHeaders
|
|
95
|
+
});
|
|
96
|
+
configObject.addPropertyAssignment({
|
|
97
|
+
name: "prompt",
|
|
98
|
+
initializer: formatStringLiteral(template)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (data.models && Object.keys(data.models).length > 0) addObjectEntries(configObject.addPropertyAssignment({
|
|
102
|
+
name: "models",
|
|
103
|
+
initializer: "{}"
|
|
104
|
+
}).getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression), data.models);
|
|
105
|
+
configObject.addPropertyAssignment({
|
|
106
|
+
name: "defaultSubAgent",
|
|
107
|
+
initializer: referenceNames.subAgents.get(data.defaultSubAgentId) ?? toCamelCase(data.defaultSubAgentId)
|
|
108
|
+
});
|
|
109
|
+
addReferenceGetterProperty(configObject, "subAgents", extractIds(data.subAgents).map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id)));
|
|
110
|
+
if (extractContextConfigId(data.contextConfig) && referenceNames.contextConfig) configObject.addPropertyAssignment({
|
|
111
|
+
name: "contextConfig",
|
|
112
|
+
initializer: referenceNames.contextConfig
|
|
113
|
+
});
|
|
114
|
+
if (data.credentials?.length) {
|
|
115
|
+
const credentialIds = data.credentials.map((credential) => {
|
|
116
|
+
if (typeof credential === "string") return credential;
|
|
117
|
+
return credential.id;
|
|
118
|
+
}).filter((id) => Boolean(id));
|
|
119
|
+
if (credentialIds.length > 0) addReferenceGetterProperty(configObject, "credentials", credentialIds.map((id) => toCamelCase(id)));
|
|
120
|
+
}
|
|
121
|
+
const triggerIds = data.triggers ? extractIds(data.triggers) : [];
|
|
122
|
+
if (triggerIds.length > 0) addReferenceGetterProperty(configObject, "triggers", triggerIds.map((id) => referenceNames.triggers.get(id) ?? toCamelCase(id)));
|
|
123
|
+
if (data.stopWhen?.transferCountIs !== void 0) configObject.addPropertyAssignment({
|
|
124
|
+
name: "stopWhen",
|
|
125
|
+
initializer: "{}"
|
|
126
|
+
}).getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression).addPropertyAssignment({
|
|
127
|
+
name: "transferCountIs",
|
|
128
|
+
initializer: String(data.stopWhen.transferCountIs)
|
|
129
|
+
});
|
|
130
|
+
if (data.statusUpdates) {
|
|
131
|
+
const statusUpdatesObject = configObject.addPropertyAssignment({
|
|
132
|
+
name: "statusUpdates",
|
|
133
|
+
initializer: "{}"
|
|
134
|
+
}).getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
135
|
+
if (data.statusUpdates.numEvents !== void 0) statusUpdatesObject.addPropertyAssignment({
|
|
136
|
+
name: "numEvents",
|
|
137
|
+
initializer: String(data.statusUpdates.numEvents)
|
|
138
|
+
});
|
|
139
|
+
if (data.statusUpdates.timeInSeconds !== void 0) statusUpdatesObject.addPropertyAssignment({
|
|
140
|
+
name: "timeInSeconds",
|
|
141
|
+
initializer: String(data.statusUpdates.timeInSeconds)
|
|
142
|
+
});
|
|
143
|
+
if (data.statusUpdates.statusComponents && data.statusUpdates.statusComponents.length > 0) {
|
|
144
|
+
const statusComponentRefs = data.statusUpdates.statusComponents.map((statusComponent) => `${referenceNames.statusComponents.get(resolveStatusComponentId(statusComponent)) ?? toCamelCase(resolveStatusComponentId(statusComponent))}.config`);
|
|
145
|
+
if (statusComponentRefs.length > 0) statusUpdatesObject.addPropertyAssignment({
|
|
146
|
+
name: "statusComponents",
|
|
147
|
+
initializer: "[]"
|
|
148
|
+
}).getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression).addElements(statusComponentRefs);
|
|
149
|
+
}
|
|
150
|
+
if (data.statusUpdates.prompt !== void 0) {
|
|
151
|
+
const template = formatTemplate(data.statusUpdates.prompt, {
|
|
152
|
+
contextReference: referenceNames.contextConfig,
|
|
153
|
+
headersReference: referenceNames.contextHeaders
|
|
154
|
+
});
|
|
155
|
+
statusUpdatesObject.addPropertyAssignment({
|
|
156
|
+
name: "prompt",
|
|
157
|
+
initializer: formatStringLiteral(template)
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function collectTemplateVariableNamesFromFields(values) {
|
|
163
|
+
const variables = [];
|
|
164
|
+
for (const value of values) {
|
|
165
|
+
if (typeof value !== "string") continue;
|
|
166
|
+
variables.push(...collectTemplateVariableNames(value));
|
|
167
|
+
}
|
|
168
|
+
return variables;
|
|
169
|
+
}
|
|
170
|
+
function extractIds(value) {
|
|
171
|
+
if (Array.isArray(value)) return value.map((item) => {
|
|
172
|
+
if (typeof item === "string") return item;
|
|
173
|
+
if (isPlainObject(item) && typeof item.id === "string") return item.id;
|
|
174
|
+
return null;
|
|
175
|
+
}).filter((id) => !!id);
|
|
176
|
+
return Object.keys(value);
|
|
177
|
+
}
|
|
178
|
+
function extractContextConfigId(contextConfig) {
|
|
179
|
+
if (!contextConfig) return;
|
|
180
|
+
if (typeof contextConfig === "string") return contextConfig;
|
|
181
|
+
return contextConfig.id;
|
|
182
|
+
}
|
|
183
|
+
function addSubAgentImports(sourceFile, referenceNames, importNames) {
|
|
184
|
+
for (const [subAgentId, referenceName] of referenceNames) {
|
|
185
|
+
const importName = importNames.get(subAgentId);
|
|
186
|
+
if (!importName) continue;
|
|
187
|
+
sourceFile.addImportDeclaration({
|
|
188
|
+
namedImports: [importName === referenceName ? importName : {
|
|
189
|
+
name: importName,
|
|
190
|
+
alias: referenceName
|
|
191
|
+
}],
|
|
192
|
+
moduleSpecifier: `./sub-agents/${subAgentId}`
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function addTriggerImports(sourceFile, referenceNames) {
|
|
197
|
+
for (const [triggerId, referenceName] of referenceNames) {
|
|
198
|
+
const importName = toCamelCase(triggerId);
|
|
199
|
+
sourceFile.addImportDeclaration({
|
|
200
|
+
namedImports: [importName === referenceName ? importName : {
|
|
201
|
+
name: importName,
|
|
202
|
+
alias: referenceName
|
|
203
|
+
}],
|
|
204
|
+
moduleSpecifier: `./triggers/${triggerId}`
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function extractStatusComponentIds(statusUpdates) {
|
|
209
|
+
if (!statusUpdates?.statusComponents?.length) return [];
|
|
210
|
+
const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);
|
|
211
|
+
return [...new Set(statusComponentIds)];
|
|
212
|
+
}
|
|
213
|
+
function resolveStatusComponentId(statusComponent) {
|
|
214
|
+
const id = typeof statusComponent === "string" ? statusComponent : statusComponent.id || statusComponent.type;
|
|
215
|
+
if (!id) throw new Error(`Unable to resolve status component with id ${JSON.stringify(statusComponent)}`);
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
function addStatusComponentImports(sourceFile, referenceNames) {
|
|
219
|
+
for (const [statusComponentId, referenceName] of referenceNames) {
|
|
220
|
+
const importName = toCamelCase(statusComponentId);
|
|
221
|
+
sourceFile.addImportDeclaration({
|
|
222
|
+
namedImports: [importName === referenceName ? importName : {
|
|
223
|
+
name: importName,
|
|
224
|
+
alias: referenceName
|
|
225
|
+
}],
|
|
226
|
+
moduleSpecifier: `../status-components/${statusComponentId}`
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function createSubAgentReferenceMaps(ids, reservedNames, conflictSuffix, overrides) {
|
|
231
|
+
const referenceNames = /* @__PURE__ */ new Map();
|
|
232
|
+
const importNames = /* @__PURE__ */ new Map();
|
|
233
|
+
for (const id of ids) {
|
|
234
|
+
if (referenceNames.has(id)) continue;
|
|
235
|
+
const override = overrides?.[id];
|
|
236
|
+
const importName = override?.name ?? toCamelCase(id);
|
|
237
|
+
const isLocal = override?.local === true;
|
|
238
|
+
const referenceName = isLocal ? importName : createUniqueReferenceName(importName, reservedNames, conflictSuffix);
|
|
239
|
+
if (isLocal) reservedNames.add(referenceName);
|
|
240
|
+
else importNames.set(id, importName);
|
|
241
|
+
referenceNames.set(id, referenceName);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
referenceNames,
|
|
245
|
+
importNames
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function createReferenceNameMap(ids, reservedNames, conflictSuffix) {
|
|
249
|
+
const map = /* @__PURE__ */ new Map();
|
|
250
|
+
for (const id of ids) {
|
|
251
|
+
if (map.has(id)) continue;
|
|
252
|
+
map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));
|
|
253
|
+
}
|
|
254
|
+
return map;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//#endregion
|
|
258
|
+
export { generateAgentDefinition };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { addValueToObject, convertJsonSchemaToZodSafe, convertNullToUndefined, createFactoryDefinition, formatPropertyName, formatStringLiteral, isPlainObject, toCamelCase } from "../utils.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/pull-v4/generators/artifact-component-generator.ts
|
|
5
|
+
const ArtifactComponentSchema = z.object({
|
|
6
|
+
artifactComponentId: z.string().nonempty(),
|
|
7
|
+
name: z.string().nonempty(),
|
|
8
|
+
description: z.string().optional(),
|
|
9
|
+
props: z.looseObject({}),
|
|
10
|
+
schema: z.looseObject({}).optional(),
|
|
11
|
+
template: z.string().optional(),
|
|
12
|
+
contentType: z.string().optional(),
|
|
13
|
+
render: z.preprocess(convertNullToUndefined, z.looseObject({
|
|
14
|
+
component: z.string().optional(),
|
|
15
|
+
mockData: z.looseObject({}).optional()
|
|
16
|
+
}).optional())
|
|
17
|
+
});
|
|
18
|
+
function generateArtifactComponentDefinition(data) {
|
|
19
|
+
const result = ArtifactComponentSchema.safeParse(data);
|
|
20
|
+
if (!result.success) throw new Error(`Validation failed for artifact component:\n${z.prettifyError(result.error)}`);
|
|
21
|
+
const parsed = result.data;
|
|
22
|
+
const schema = parsed.props ?? parsed.schema;
|
|
23
|
+
const { sourceFile, configObject } = createFactoryDefinition({
|
|
24
|
+
importName: "artifactComponent",
|
|
25
|
+
variableName: toCamelCase(parsed.artifactComponentId)
|
|
26
|
+
});
|
|
27
|
+
if (hasInPreviewFields(schema)) sourceFile.addImportDeclaration({
|
|
28
|
+
namedImports: ["preview"],
|
|
29
|
+
moduleSpecifier: "@inkeep/agents-core"
|
|
30
|
+
});
|
|
31
|
+
if (schema) sourceFile.addImportDeclaration({
|
|
32
|
+
namedImports: ["z"],
|
|
33
|
+
moduleSpecifier: "zod"
|
|
34
|
+
});
|
|
35
|
+
const { artifactComponentId, schema: _, props: _2, ...rest } = parsed;
|
|
36
|
+
for (const [key, value] of Object.entries({
|
|
37
|
+
id: artifactComponentId,
|
|
38
|
+
...rest
|
|
39
|
+
})) addValueToObject(configObject, key, value);
|
|
40
|
+
if (schema) configObject.addPropertyAssignment({
|
|
41
|
+
name: "props",
|
|
42
|
+
initializer: formatArtifactSchema(schema)
|
|
43
|
+
});
|
|
44
|
+
return sourceFile;
|
|
45
|
+
}
|
|
46
|
+
function hasInPreviewFields(schema) {
|
|
47
|
+
if (!isPlainObject(schema) || schema.type !== "object" || !isPlainObject(schema.properties)) return false;
|
|
48
|
+
return Object.values(schema.properties).some((property) => isPlainObject(property) && property.inPreview === true);
|
|
49
|
+
}
|
|
50
|
+
function formatArtifactSchema(schema) {
|
|
51
|
+
if (!isPlainObject(schema)) return "z.any()";
|
|
52
|
+
if (schema.type === "object" && isPlainObject(schema.properties)) {
|
|
53
|
+
const lines = ["z.object({"];
|
|
54
|
+
for (const [key, propertySchema] of Object.entries(schema.properties)) {
|
|
55
|
+
const propertyWithoutPreview = isPlainObject(propertySchema) ? { ...propertySchema } : propertySchema;
|
|
56
|
+
if (isPlainObject(propertyWithoutPreview)) delete propertyWithoutPreview.inPreview;
|
|
57
|
+
const zodType = convertJsonSchemaToZodSafe(propertyWithoutPreview);
|
|
58
|
+
const propertyValue = isPlainObject(propertySchema) && propertySchema.inPreview === true ? `preview(${zodType})` : zodType;
|
|
59
|
+
lines.push(` ${formatPropertyName(key)}: ${propertyValue},`);
|
|
60
|
+
}
|
|
61
|
+
lines.push("})");
|
|
62
|
+
if (typeof schema.description === "string") return `${lines.join("\n")}.describe(${formatStringLiteral(schema.description)})`;
|
|
63
|
+
return lines.join("\n");
|
|
64
|
+
}
|
|
65
|
+
return convertJsonSchemaToZodSafe(schema);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { generateArtifactComponentDefinition };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { addFactoryConfigVariable, addStringProperty, addValueToObject, convertJsonSchemaToZodSafe, convertNullToUndefined, createInMemoryProject, formatPropertyName, isPlainObject, toCamelCase } from "../utils.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { SyntaxKind } from "ts-morph";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/pull-v4/generators/context-config-generator.ts
|
|
6
|
+
const ReferenceNameByIdSchema = z.record(z.string(), z.string().nonempty());
|
|
7
|
+
const ReferenceOverridesSchema = z.object({ credentialReferences: ReferenceNameByIdSchema.optional() });
|
|
8
|
+
const ContextConfigSchema = z.looseObject({
|
|
9
|
+
contextConfigId: z.string().nonempty(),
|
|
10
|
+
id: z.string().optional(),
|
|
11
|
+
schema: z.looseObject({}).optional(),
|
|
12
|
+
headers: z.union([z.string(), z.looseObject({ id: z.string().optional() })]).optional(),
|
|
13
|
+
headersSchema: z.preprocess(convertNullToUndefined, z.looseObject({}).optional()),
|
|
14
|
+
contextVariables: z.record(z.string(), z.unknown()).optional(),
|
|
15
|
+
referenceOverrides: ReferenceOverridesSchema.optional()
|
|
16
|
+
});
|
|
17
|
+
function generateContextConfigDefinition(data) {
|
|
18
|
+
const result = ContextConfigSchema.safeParse(data);
|
|
19
|
+
if (!result.success) throw new Error(`Validation failed for context config:\n${z.prettifyError(result.error)}`);
|
|
20
|
+
const project = createInMemoryProject();
|
|
21
|
+
const parsed = result.data;
|
|
22
|
+
const sourceFile = project.createSourceFile("context-config-definition.ts", "", { overwrite: true });
|
|
23
|
+
if (isHeadersDefinitionData(parsed)) return generateStandaloneHeadersDefinition(sourceFile, parsed);
|
|
24
|
+
if (isFetchDefinitionData(parsed)) return generateStandaloneFetchDefinition(sourceFile, parsed);
|
|
25
|
+
const parsedContextConfig = result.data;
|
|
26
|
+
const explicitHeadersReference = extractHeadersReference(parsedContextConfig.headers);
|
|
27
|
+
const templateHeaderVariables = collectTemplateHeaderVariables(parsedContextConfig.contextVariables);
|
|
28
|
+
const inferredHeadersSchema = !isPlainObject(parsedContextConfig.headersSchema) && !explicitHeadersReference ? inferHeadersSchemaFromTemplateHeaderVariables(templateHeaderVariables) : void 0;
|
|
29
|
+
const headersSchema = isPlainObject(parsedContextConfig.headersSchema) ? parsedContextConfig.headersSchema : inferredHeadersSchema;
|
|
30
|
+
const headersReference = resolveHeadersReference(parsedContextConfig, Boolean(headersSchema));
|
|
31
|
+
const shouldDefineHeadersInFile = Boolean(headersReference) && isPlainObject(headersSchema);
|
|
32
|
+
const fetchDefinitions = collectFetchDefinitionEntries(parsedContextConfig.contextVariables);
|
|
33
|
+
const credentialReferenceNames = collectCredentialReferenceNames(fetchDefinitions, parsedContextConfig.referenceOverrides?.credentialReferences);
|
|
34
|
+
const coreImports = ["contextConfig"];
|
|
35
|
+
if (shouldDefineHeadersInFile) coreImports.unshift("headers");
|
|
36
|
+
if (fetchDefinitions.length > 0) coreImports.splice(coreImports.length - 1, 0, "fetchDefinition");
|
|
37
|
+
sourceFile.addImportDeclaration({
|
|
38
|
+
namedImports: coreImports,
|
|
39
|
+
moduleSpecifier: "@inkeep/agents-core"
|
|
40
|
+
});
|
|
41
|
+
const hasResponseSchemas = fetchDefinitions.some((definition) => isPlainObject(definition.data.responseSchema));
|
|
42
|
+
if (shouldDefineHeadersInFile || hasResponseSchemas) sourceFile.addImportDeclaration({
|
|
43
|
+
namedImports: ["z"],
|
|
44
|
+
moduleSpecifier: "zod"
|
|
45
|
+
});
|
|
46
|
+
for (const [credentialId, credentialReferenceName] of credentialReferenceNames) sourceFile.addImportDeclaration({
|
|
47
|
+
namedImports: [credentialReferenceName],
|
|
48
|
+
moduleSpecifier: `../credentials/${credentialId}`
|
|
49
|
+
});
|
|
50
|
+
if (shouldDefineHeadersInFile && headersReference && headersSchema) {
|
|
51
|
+
const { configObject: headersObject } = addFactoryConfigVariable({
|
|
52
|
+
sourceFile,
|
|
53
|
+
importName: "headers",
|
|
54
|
+
variableName: headersReference
|
|
55
|
+
});
|
|
56
|
+
headersObject.addPropertyAssignment({
|
|
57
|
+
name: "schema",
|
|
58
|
+
initializer: convertJsonSchemaToZod(headersSchema)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
for (const fetchDefinition of fetchDefinitions) {
|
|
62
|
+
const { configObject: fetchConfigObject } = addFactoryConfigVariable({
|
|
63
|
+
sourceFile,
|
|
64
|
+
importName: "fetchDefinition",
|
|
65
|
+
variableName: fetchDefinition.variableName
|
|
66
|
+
});
|
|
67
|
+
writeFetchDefinition(fetchConfigObject, fetchDefinition.data, credentialReferenceNames, headersReference);
|
|
68
|
+
}
|
|
69
|
+
const { configObject } = addFactoryConfigVariable({
|
|
70
|
+
sourceFile,
|
|
71
|
+
importName: "contextConfig",
|
|
72
|
+
variableName: toContextConfigVariableName(parsedContextConfig.contextConfigId),
|
|
73
|
+
isExported: true
|
|
74
|
+
});
|
|
75
|
+
writeContextConfig(configObject, parsedContextConfig, headersReference);
|
|
76
|
+
return sourceFile;
|
|
77
|
+
}
|
|
78
|
+
function writeContextConfig(configObject, data, headersReference) {
|
|
79
|
+
if (data.id !== void 0) addStringProperty(configObject, "id", data.id);
|
|
80
|
+
if (headersReference) configObject.addPropertyAssignment({
|
|
81
|
+
name: "headers",
|
|
82
|
+
initializer: headersReference
|
|
83
|
+
});
|
|
84
|
+
if (data.contextVariables && Object.keys(data.contextVariables).length > 0) {
|
|
85
|
+
const contextVariablesObject = configObject.addPropertyAssignment({
|
|
86
|
+
name: "contextVariables",
|
|
87
|
+
initializer: "{}"
|
|
88
|
+
}).getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
89
|
+
for (const [key, value] of Object.entries(data.contextVariables)) {
|
|
90
|
+
const reference = extractContextVariableReference(key, value);
|
|
91
|
+
if (!reference) continue;
|
|
92
|
+
contextVariablesObject.addPropertyAssignment({
|
|
93
|
+
name: formatPropertyName(key),
|
|
94
|
+
initializer: reference
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function extractHeadersReference(headers) {
|
|
100
|
+
if (!headers) return;
|
|
101
|
+
if (typeof headers === "string") return headers;
|
|
102
|
+
if (typeof headers.id === "string") return headers.id;
|
|
103
|
+
if (typeof headers.name === "string") return headers.name;
|
|
104
|
+
}
|
|
105
|
+
function resolveHeadersReference(data, hasHeadersSchema) {
|
|
106
|
+
const headersRef = extractHeadersReference(data.headers);
|
|
107
|
+
if (headersRef) return toReferenceIdentifier(headersRef);
|
|
108
|
+
if (hasHeadersSchema) return `${toContextConfigVariableName(data.contextConfigId)}Headers`;
|
|
109
|
+
}
|
|
110
|
+
function isFetchDefinitionData(value) {
|
|
111
|
+
if (!isPlainObject(value)) return false;
|
|
112
|
+
return value.fetchConfig !== void 0 || value.responseSchema !== void 0;
|
|
113
|
+
}
|
|
114
|
+
function collectFetchDefinitionEntries(contextVariables) {
|
|
115
|
+
if (!contextVariables) return [];
|
|
116
|
+
return Object.entries(contextVariables).filter(([, value]) => isFetchDefinitionData(value)).map(([key, value]) => {
|
|
117
|
+
return {
|
|
118
|
+
key,
|
|
119
|
+
variableName: extractContextVariableReference(key, value) ?? toReferenceIdentifier(key),
|
|
120
|
+
data: value
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function writeFetchDefinition(configObject, fetchDefinitionData, credentialReferenceNames, headersReference) {
|
|
125
|
+
const { contextConfigId, responseSchema, credentialReferenceId, ...rest } = isPlainObject(fetchDefinitionData) ? fetchDefinitionData : {};
|
|
126
|
+
const normalizedRest = rewriteHeaderTemplates(rest, headersReference);
|
|
127
|
+
for (const [k, v] of Object.entries({
|
|
128
|
+
id: contextConfigId,
|
|
129
|
+
...normalizedRest
|
|
130
|
+
})) if (v !== null) addValueToObject(configObject, k, v);
|
|
131
|
+
if (responseSchema) configObject.addPropertyAssignment({
|
|
132
|
+
name: "responseSchema",
|
|
133
|
+
initializer: convertJsonSchemaToZod(responseSchema)
|
|
134
|
+
});
|
|
135
|
+
if (typeof credentialReferenceId === "string" && credentialReferenceNames?.has(credentialReferenceId)) {
|
|
136
|
+
configObject.addPropertyAssignment({
|
|
137
|
+
name: "credentialReference",
|
|
138
|
+
initializer: credentialReferenceNames.get(credentialReferenceId)
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (typeof credentialReferenceId === "string") addStringProperty(configObject, "credentialReferenceId", credentialReferenceId);
|
|
143
|
+
}
|
|
144
|
+
const HEADER_TEMPLATE_REGEX = /\{\{headers\.([^}]+)\}\}/g;
|
|
145
|
+
const HEADER_TO_TEMPLATE_CALL_REGEX = /\$\{\s*(headersSchema|headers)\.toTemplate\((['"])([^'"`]+)\2\)\s*\}/g;
|
|
146
|
+
function rewriteHeaderTemplates(value, headersReference) {
|
|
147
|
+
if (!headersReference) return value;
|
|
148
|
+
if (typeof value === "string") return value.replace(HEADER_TEMPLATE_REGEX, (_, variableName) => {
|
|
149
|
+
return `\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;
|
|
150
|
+
}).replace(HEADER_TO_TEMPLATE_CALL_REGEX, (_, __, ___, variableName) => {
|
|
151
|
+
return `\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;
|
|
152
|
+
});
|
|
153
|
+
if (Array.isArray(value)) return value.map((entry) => rewriteHeaderTemplates(entry, headersReference));
|
|
154
|
+
if (isPlainObject(value)) return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, rewriteHeaderTemplates(entryValue, headersReference)]));
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function generateStandaloneHeadersDefinition(sourceFile, data) {
|
|
158
|
+
const importName = "headers";
|
|
159
|
+
sourceFile.addImportDeclaration({
|
|
160
|
+
namedImports: [importName],
|
|
161
|
+
moduleSpecifier: "@inkeep/agents-core"
|
|
162
|
+
});
|
|
163
|
+
sourceFile.addImportDeclaration({
|
|
164
|
+
namedImports: ["z"],
|
|
165
|
+
moduleSpecifier: "zod"
|
|
166
|
+
});
|
|
167
|
+
const { configObject } = addFactoryConfigVariable({
|
|
168
|
+
sourceFile,
|
|
169
|
+
importName,
|
|
170
|
+
variableName: toContextConfigVariableName(data.contextConfigId)
|
|
171
|
+
});
|
|
172
|
+
configObject.addPropertyAssignment({
|
|
173
|
+
name: "schema",
|
|
174
|
+
initializer: convertJsonSchemaToZod(data.schema)
|
|
175
|
+
});
|
|
176
|
+
return sourceFile;
|
|
177
|
+
}
|
|
178
|
+
function isHeadersDefinitionData(value) {
|
|
179
|
+
return isPlainObject(value.schema);
|
|
180
|
+
}
|
|
181
|
+
function generateStandaloneFetchDefinition(sourceFile, data) {
|
|
182
|
+
const importName = "fetchDefinition";
|
|
183
|
+
sourceFile.addImportDeclaration({
|
|
184
|
+
namedImports: [importName],
|
|
185
|
+
moduleSpecifier: "@inkeep/agents-core"
|
|
186
|
+
});
|
|
187
|
+
if (isPlainObject(data.responseSchema)) sourceFile.addImportDeclaration({
|
|
188
|
+
namedImports: ["z"],
|
|
189
|
+
moduleSpecifier: "zod"
|
|
190
|
+
});
|
|
191
|
+
const credentialReferenceNames = /* @__PURE__ */ new Map();
|
|
192
|
+
if (typeof data.credentialReferenceId === "string") {
|
|
193
|
+
const credentialReferenceId = data.credentialReferenceId;
|
|
194
|
+
const credentialReferenceName = data.referenceOverrides?.credentialReferences?.[credentialReferenceId] ?? toReferenceIdentifier(credentialReferenceId);
|
|
195
|
+
credentialReferenceNames.set(credentialReferenceId, credentialReferenceName);
|
|
196
|
+
sourceFile.addImportDeclaration({
|
|
197
|
+
namedImports: [credentialReferenceName],
|
|
198
|
+
moduleSpecifier: `../credentials/${credentialReferenceId}`
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const { configObject } = addFactoryConfigVariable({
|
|
202
|
+
sourceFile,
|
|
203
|
+
importName,
|
|
204
|
+
variableName: toContextConfigVariableName(data.contextConfigId)
|
|
205
|
+
});
|
|
206
|
+
writeFetchDefinition(configObject, data, credentialReferenceNames);
|
|
207
|
+
return sourceFile;
|
|
208
|
+
}
|
|
209
|
+
function convertJsonSchemaToZod(schema) {
|
|
210
|
+
return convertJsonSchemaToZodSafe(schema, { conversionOptions: { module: "none" } });
|
|
211
|
+
}
|
|
212
|
+
function extractContextVariableReference(key, value) {
|
|
213
|
+
if (typeof value === "string") return toReferenceIdentifier(value);
|
|
214
|
+
if (!isPlainObject(value)) return;
|
|
215
|
+
if (typeof value.id === "string") return toReferenceIdentifier(value.id);
|
|
216
|
+
if (typeof value.name === "string") return toReferenceIdentifier(value.name);
|
|
217
|
+
if (typeof value.ref === "string") return toReferenceIdentifier(value.ref);
|
|
218
|
+
if (typeof value.variable === "string") return toReferenceIdentifier(value.variable);
|
|
219
|
+
if (value.fetchConfig || value.responseSchema) return toReferenceIdentifier(key);
|
|
220
|
+
return toReferenceIdentifier(key);
|
|
221
|
+
}
|
|
222
|
+
const toContextConfigVariableName = toCamelCase;
|
|
223
|
+
const toReferenceIdentifier = toCamelCase;
|
|
224
|
+
function collectCredentialReferenceNames(fetchDefinitions, overrideNamesById) {
|
|
225
|
+
const credentialReferenceNames = /* @__PURE__ */ new Map();
|
|
226
|
+
for (const fetchDefinition of fetchDefinitions) {
|
|
227
|
+
const fetchDefinitionData = isPlainObject(fetchDefinition.data) ? fetchDefinition.data : void 0;
|
|
228
|
+
const credentialReferenceId = fetchDefinitionData && typeof fetchDefinitionData.credentialReferenceId === "string" ? fetchDefinitionData.credentialReferenceId : void 0;
|
|
229
|
+
if (!credentialReferenceId || credentialReferenceNames.has(credentialReferenceId)) continue;
|
|
230
|
+
credentialReferenceNames.set(credentialReferenceId, overrideNamesById?.[credentialReferenceId] ?? toReferenceIdentifier(credentialReferenceId));
|
|
231
|
+
}
|
|
232
|
+
return credentialReferenceNames;
|
|
233
|
+
}
|
|
234
|
+
function collectTemplateHeaderVariables(contextVariables) {
|
|
235
|
+
const variables = /* @__PURE__ */ new Set();
|
|
236
|
+
collectTemplateHeaderVariablesFromValue(contextVariables, variables);
|
|
237
|
+
return variables;
|
|
238
|
+
}
|
|
239
|
+
function collectTemplateHeaderVariablesFromValue(value, variables) {
|
|
240
|
+
if (typeof value === "string") {
|
|
241
|
+
for (const match of value.matchAll(HEADER_TEMPLATE_REGEX)) if (match[1]) variables.add(match[1]);
|
|
242
|
+
for (const match of value.matchAll(HEADER_TO_TEMPLATE_CALL_REGEX)) if (match[3]) variables.add(match[3]);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (Array.isArray(value)) {
|
|
246
|
+
for (const entry of value) collectTemplateHeaderVariablesFromValue(entry, variables);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (isPlainObject(value)) for (const entryValue of Object.values(value)) collectTemplateHeaderVariablesFromValue(entryValue, variables);
|
|
250
|
+
}
|
|
251
|
+
function inferHeadersSchemaFromTemplateHeaderVariables(variables) {
|
|
252
|
+
if (!variables.size) return;
|
|
253
|
+
const properties = {};
|
|
254
|
+
for (const variable of [...variables].sort()) properties[variable] = { type: "string" };
|
|
255
|
+
return {
|
|
256
|
+
type: "object",
|
|
257
|
+
properties,
|
|
258
|
+
required: [...variables].sort(),
|
|
259
|
+
additionalProperties: false
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
export { generateContextConfigDefinition };
|