@inkeep/agents-cli 0.59.3 → 0.60.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 +1 -1
- package/dist/commands/pull-v4/collector-common.js +128 -0
- package/dist/commands/pull-v4/collector-common.js.map +1 -0
- package/dist/commands/pull-v4/collector-reference-helpers.js +323 -0
- package/dist/commands/pull-v4/collector-reference-helpers.js.map +1 -0
- package/dist/commands/pull-v4/component-parser.js +2 -1
- package/dist/commands/pull-v4/component-parser.js.map +1 -1
- package/dist/commands/pull-v4/file-scope.js +43 -0
- package/dist/commands/pull-v4/file-scope.js.map +1 -0
- package/dist/commands/pull-v4/generation-resolver.js +305 -0
- package/dist/commands/pull-v4/generation-resolver.js.map +1 -0
- package/dist/commands/pull-v4/generation-types.js +56 -0
- package/dist/commands/pull-v4/generation-types.js.map +1 -0
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js +4 -10
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js.map +1 -1
- package/dist/commands/pull-v4/generators/agent-generator.js +154 -81
- package/dist/commands/pull-v4/generators/agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/artifact-component-generator.js +48 -27
- package/dist/commands/pull-v4/generators/artifact-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/context-config-generator.js +147 -129
- package/dist/commands/pull-v4/generators/context-config-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/credential-generator.js +36 -14
- package/dist/commands/pull-v4/generators/credential-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/data-component-generator.js +55 -19
- package/dist/commands/pull-v4/generators/data-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/environment-generator.js +29 -33
- package/dist/commands/pull-v4/generators/environment-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/environment-settings-generator.js +57 -0
- package/dist/commands/pull-v4/generators/environment-settings-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/external-agent-generator.js +51 -23
- package/dist/commands/pull-v4/generators/external-agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/function-tool-generator.js +50 -14
- package/dist/commands/pull-v4/generators/function-tool-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/helpers/agent.js +129 -0
- package/dist/commands/pull-v4/generators/helpers/agent.js.map +1 -0
- package/dist/commands/pull-v4/generators/helpers/sub-agent.js +65 -0
- package/dist/commands/pull-v4/generators/helpers/sub-agent.js.map +1 -0
- package/dist/commands/pull-v4/generators/index.js +38 -0
- package/dist/commands/pull-v4/generators/index.js.map +1 -0
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js +48 -27
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/project-generator.js +144 -110
- package/dist/commands/pull-v4/generators/project-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/scheduled-trigger-generator.js +66 -0
- package/dist/commands/pull-v4/generators/scheduled-trigger-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/status-component-generator.js +55 -20
- package/dist/commands/pull-v4/generators/status-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js +4 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js.map +1 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.js +282 -166
- package/dist/commands/pull-v4/generators/sub-agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/trigger-generator.js +62 -27
- package/dist/commands/pull-v4/generators/trigger-generator.js.map +1 -1
- package/dist/commands/pull-v4/import-plan.js +40 -0
- package/dist/commands/pull-v4/import-plan.js.map +1 -0
- package/dist/commands/pull-v4/introspect/index.js +11 -7
- package/dist/commands/pull-v4/introspect/index.js.map +1 -1
- package/dist/commands/pull-v4/introspect-generator.js +15 -1218
- package/dist/commands/pull-v4/introspect-generator.js.map +1 -1
- package/dist/commands/pull-v4/module-merge.js +14 -5
- package/dist/commands/pull-v4/module-merge.js.map +1 -1
- package/dist/commands/pull-v4/reference-resolution.js +111 -0
- package/dist/commands/pull-v4/reference-resolution.js.map +1 -0
- package/dist/commands/pull-v4/simple-factory-generator.js +54 -0
- package/dist/commands/pull-v4/simple-factory-generator.js.map +1 -0
- package/dist/commands/pull-v4/{generators/skill-generator.js → skill.js} +18 -6
- package/dist/commands/pull-v4/skill.js.map +1 -0
- package/dist/commands/pull-v4/typescript-file-writer.js +78 -0
- package/dist/commands/pull-v4/typescript-file-writer.js.map +1 -0
- package/dist/commands/pull-v4/utils/code-values.js +64 -0
- package/dist/commands/pull-v4/utils/code-values.js.map +1 -0
- package/dist/commands/pull-v4/utils/factory-writer.js +128 -0
- package/dist/commands/pull-v4/utils/factory-writer.js.map +1 -0
- package/dist/commands/pull-v4/utils/index.js +8 -0
- package/dist/commands/pull-v4/utils/naming.js +74 -0
- package/dist/commands/pull-v4/utils/naming.js.map +1 -0
- package/dist/commands/pull-v4/utils/schema-rendering.js +20 -0
- package/dist/commands/pull-v4/utils/schema-rendering.js.map +1 -0
- package/dist/commands/pull-v4/utils/shared.js +18 -0
- package/dist/commands/pull-v4/utils/shared.js.map +1 -0
- package/dist/commands/pull-v4/utils/templates.js +58 -0
- package/dist/commands/pull-v4/utils/templates.js.map +1 -0
- package/package.json +4 -4
- package/dist/commands/pull-v4/generators/skill-generator.js.map +0 -1
- package/dist/commands/pull-v4/scheduled-trigger-generator.js +0 -38
- package/dist/commands/pull-v4/scheduled-trigger-generator.js.map +0 -1
- package/dist/commands/pull-v4/utils.js +0 -320
- package/dist/commands/pull-v4/utils.js.map +0 -1
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPlainObject } from "../utils/shared.js";
|
|
2
|
+
import { createUniqueReferenceName, toCamelCase, toKebabCase, toTriggerReferenceName } from "../utils/naming.js";
|
|
3
|
+
import "../utils/index.js";
|
|
2
4
|
|
|
3
5
|
//#region src/commands/pull-v4/generators/agent-generator.helpers.ts
|
|
4
|
-
function collectTemplateVariableNamesFromFields(values) {
|
|
5
|
-
const variables = [];
|
|
6
|
-
for (const value of values) {
|
|
7
|
-
if (typeof value !== "string") continue;
|
|
8
|
-
variables.push(...collectTemplateVariableNames(value));
|
|
9
|
-
}
|
|
10
|
-
return variables;
|
|
11
|
-
}
|
|
12
6
|
function extractIds(value) {
|
|
13
7
|
if (Array.isArray(value)) return value.map((item) => {
|
|
14
8
|
if (typeof item === "string") return item;
|
|
@@ -182,5 +176,5 @@ function createNumericReferenceName(baseName, reservedNames) {
|
|
|
182
176
|
}
|
|
183
177
|
|
|
184
178
|
//#endregion
|
|
185
|
-
export { addScheduledTriggerImports, addStatusComponentImports, addSubAgentImports, addTriggerImports,
|
|
179
|
+
export { addScheduledTriggerImports, addStatusComponentImports, addSubAgentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createSubAgentReferenceMaps, createTriggerReferenceMaps, extractContextConfigId, extractIds, extractStatusComponentIds, resolveStatusComponentId };
|
|
186
180
|
//# sourceMappingURL=agent-generator.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-generator.helpers.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.helpers.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n collectTemplateVariableNames,\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\ninterface SubAgentReferenceOverride {\n name: string;\n local?: boolean;\n}\n\ntype StatusComponentLike = string | { id?: string; type?: string; name?: string };\ntype StatusUpdatesLike = { statusComponents?: StatusComponentLike[] } | undefined;\n\nexport function collectTemplateVariableNamesFromFields(\n values: Array<string | undefined>\n): string[] {\n const variables: string[] = [];\n for (const value of values) {\n if (typeof value !== 'string') {\n continue;\n }\n variables.push(...collectTemplateVariableNames(value));\n }\n return variables;\n}\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function extractContextConfigId(\n contextConfig?: string | { id?: string }\n): string | undefined {\n if (!contextConfig) {\n return;\n }\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n return contextConfig.id;\n}\n\nexport function addSubAgentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importNames: ReferenceNameMap,\n modulePathOverrides?: Record<string, string>\n): void {\n for (const [subAgentId, referenceName] of referenceNames) {\n const importName = importNames.get(subAgentId);\n if (!importName) {\n continue;\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./sub-agents/${modulePathOverrides?.[subAgentId] ?? subAgentId}`,\n });\n }\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./triggers/${modulePath}`,\n });\n }\n}\n\nexport function addScheduledTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [scheduledTriggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(scheduledTriggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./scheduled-triggers/${modulePath}`,\n });\n }\n}\n\nexport function extractStatusComponentIds(statusUpdates: StatusUpdatesLike): string[] {\n if (!statusUpdates?.statusComponents?.length) {\n return [];\n }\n\n const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);\n return [...new Set(statusComponentIds)];\n}\n\nexport function resolveStatusComponentId(statusComponent: StatusComponentLike): string {\n const id =\n typeof statusComponent === 'string'\n ? statusComponent\n : statusComponent.id || statusComponent.type;\n if (!id) {\n throw new Error(\n `Unable to resolve status component with id ${JSON.stringify(statusComponent)}`\n );\n }\n return id;\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `../status-components/${statusComponentId}`,\n });\n }\n}\n\nexport function createSubAgentReferenceMaps(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string,\n overrides?: Record<string, SubAgentReferenceOverride>\n): {\n referenceNames: ReferenceNameMap;\n importNames: ReferenceNameMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importNames: ReferenceNameMap = new Map();\n\n for (const id of ids) {\n if (referenceNames.has(id)) {\n continue;\n }\n\n const override = overrides?.[id];\n const importName = override?.name ?? toCamelCase(id);\n const isLocal = override?.local === true;\n const referenceName = isLocal\n ? importName\n : createUniqueReferenceName(importName, reservedNames, conflictSuffix);\n\n if (isLocal) {\n reservedNames.add(referenceName);\n } else {\n importNames.set(id, importName);\n }\n\n referenceNames.set(id, referenceName);\n }\n\n return { referenceNames, importNames };\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createScheduledTriggerReferenceMaps(\n scheduledTriggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {\n if (referenceNames.has(scheduledTriggerId)) {\n continue;\n }\n\n const scheduledTriggerRecord = isPlainObject(scheduledTriggerData)\n ? scheduledTriggerData\n : undefined;\n const scheduledTriggerName =\n typeof scheduledTriggerRecord?.name === 'string' && scheduledTriggerRecord.name.length > 0\n ? scheduledTriggerRecord.name\n : scheduledTriggerId;\n\n const importName = toTriggerReferenceName(scheduledTriggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName =\n toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(scheduledTriggerId, referenceName);\n importRefs.set(scheduledTriggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n"],"mappings":";;;AAqBA,SAAgB,uCACd,QACU;CACV,MAAM,YAAsB,EAAE;AAC9B,MAAK,MAAM,SAAS,QAAQ;AAC1B,MAAI,OAAO,UAAU,SACnB;AAEF,YAAU,KAAK,GAAG,6BAA6B,MAAM,CAAC;;AAExD,QAAO;;AAGT,SAAgB,WAAW,OAAsD;AAC/E,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,OAAO,SAAS,SAClB,QAAO;AAET,MAAI,cAAc,KAAK,IAAI,OAAO,KAAK,OAAO,SAC5C,QAAO,KAAK;AAEd,SAAO;GACP,CACD,QAAQ,OAAqB,QAAQ,GAAG,CAAC;AAE9C,QAAO,OAAO,KAAK,MAAM;;AAG3B,SAAgB,uBACd,eACoB;AACpB,KAAI,CAAC,cACH;AAEF,KAAI,OAAO,kBAAkB,SAC3B,QAAO;AAET,QAAO,cAAc;;AAGvB,SAAgB,mBACd,YACA,gBACA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gB,IAAI,iBAAiB,GAAG,eAAe,GAAG;AAE7E,iBAAe,IAAI,WAAW,cAAc;AAC5C,aAAW,IAAI,WAAW;GAAE;GAAY;GAAY,CAAC;;AAGvD,QAAO;EAAE;EAAgB;EAAY;;AAGvC,SAAS,2BAA2B,UAAkB,eAAoC;AACxF,KAAI,CAAC,cAAc,IAAI,SAAS,EAAE;AAChC,gBAAc,IAAI,SAAS;AAC3B,SAAO;;CAGT,IAAI,QAAQ;AACZ,QAAO,cAAc,IAAI,GAAG,WAAW,QAAQ,CAC7C,UAAS;CAGX,MAAM,aAAa,GAAG,WAAW;AACjC,eAAc,IAAI,WAAW;AAC7B,QAAO"}
|
|
1
|
+
{"version":3,"file":"agent-generator.helpers.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.helpers.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\ninterface SubAgentReferenceOverride {\n name: string;\n local?: boolean;\n}\n\ntype StatusComponentLike = string | { id?: string; type?: string; name?: string };\ntype StatusUpdatesLike = { statusComponents?: StatusComponentLike[] } | undefined;\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function extractContextConfigId(\n contextConfig?: string | { id?: string }\n): string | undefined {\n if (!contextConfig) {\n return;\n }\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n return contextConfig.id;\n}\n\nexport function addSubAgentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importNames: ReferenceNameMap,\n modulePathOverrides?: Record<string, string>\n): void {\n for (const [subAgentId, referenceName] of referenceNames) {\n const importName = importNames.get(subAgentId);\n if (!importName) {\n continue;\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./sub-agents/${modulePathOverrides?.[subAgentId] ?? subAgentId}`,\n });\n }\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./triggers/${modulePath}`,\n });\n }\n}\n\nexport function addScheduledTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [scheduledTriggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(scheduledTriggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./scheduled-triggers/${modulePath}`,\n });\n }\n}\n\nexport function extractStatusComponentIds(statusUpdates: StatusUpdatesLike): string[] {\n if (!statusUpdates?.statusComponents?.length) {\n return [];\n }\n\n const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);\n return [...new Set(statusComponentIds)];\n}\n\nexport function resolveStatusComponentId(statusComponent: StatusComponentLike): string {\n const id =\n typeof statusComponent === 'string'\n ? statusComponent\n : statusComponent.id || statusComponent.type;\n if (!id) {\n throw new Error(\n `Unable to resolve status component with id ${JSON.stringify(statusComponent)}`\n );\n }\n return id;\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `../status-components/${statusComponentId}`,\n });\n }\n}\n\nexport function createSubAgentReferenceMaps(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string,\n overrides?: Record<string, SubAgentReferenceOverride>\n): {\n referenceNames: ReferenceNameMap;\n importNames: ReferenceNameMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importNames: ReferenceNameMap = new Map();\n\n for (const id of ids) {\n if (referenceNames.has(id)) {\n continue;\n }\n\n const override = overrides?.[id];\n const importName = override?.name ?? toCamelCase(id);\n const isLocal = override?.local === true;\n const referenceName = isLocal\n ? importName\n : createUniqueReferenceName(importName, reservedNames, conflictSuffix);\n\n if (isLocal) {\n reservedNames.add(referenceName);\n } else {\n importNames.set(id, importName);\n }\n\n referenceNames.set(id, referenceName);\n }\n\n return { referenceNames, importNames };\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createScheduledTriggerReferenceMaps(\n scheduledTriggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {\n if (referenceNames.has(scheduledTriggerId)) {\n continue;\n }\n\n const scheduledTriggerRecord = isPlainObject(scheduledTriggerData)\n ? scheduledTriggerData\n : undefined;\n const scheduledTriggerName =\n typeof scheduledTriggerRecord?.name === 'string' && scheduledTriggerRecord.name.length > 0\n ? scheduledTriggerRecord.name\n : scheduledTriggerId;\n\n const importName = toTriggerReferenceName(scheduledTriggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName =\n toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(scheduledTriggerId, referenceName);\n importRefs.set(scheduledTriggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n"],"mappings":";;;;;AAoBA,SAAgB,WAAW,OAAsD;AAC/E,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,OAAO,SAAS,SAClB,QAAO;AAET,MAAI,cAAc,KAAK,IAAI,OAAO,KAAK,OAAO,SAC5C,QAAO,KAAK;AAEd,SAAO;GACP,CACD,QAAQ,OAAqB,QAAQ,GAAG,CAAC;AAE9C,QAAO,OAAO,KAAK,MAAM;;AAG3B,SAAgB,uBACd,eACoB;AACpB,KAAI,CAAC,cACH;AAEF,KAAI,OAAO,kBAAkB,SAC3B,QAAO;AAET,QAAO,cAAc;;AAGvB,SAAgB,mBACd,YACA,gBACA,aACA,qBACM;AACN,MAAK,MAAM,CAAC,YAAY,kBAAkB,gBAAgB;EACxD,MAAM,aAAa,YAAY,IAAI,WAAW;AAC9C,MAAI,CAAC,WACH;AAGF,aAAW,qBAAqB;GAC9B,cAAc,CACZ,eAAe,gBAAgB,aAAa;IAAE,MAAM;IAAY,OAAO;IAAe,CACvF;GACD,iBAAiB,gBAAgB,sBAAsB,eAAe;GACvE,CAAC;;;AAIN,SAAgB,kBACd,YACA,gBACA,YACM;AACN,MAAK,MAAM,CAAC,WAAW,kBAAkB,gBAAgB;EACvD,MAAM,YAAY,WAAW,IAAI,UAAU;AAC3C,MAAI,CAAC,UACH;EAGF,MAAM,EAAE,YAAY,eAAe;AACnC,aAAW,qBAAqB;GAC9B,cAAc,CACZ,eAAe,gBAAgB,aAAa;IAAE,MAAM;IAAY,OAAO;IAAe,CACvF;GACD,iBAAiB,cAAc;GAChC,CAAC;;;AAIN,SAAgB,2BACd,Y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,eAIA;CACA,MAAM,iCAAmC,IAAI,KAAK;CAClD,MAAM,6BAA+B,IAAI,KAAK;AAE9C,KAAI,CAAC,YAAY,CAAC,cAAc,SAAS,CACvC,QAAO;EAAE;EAAgB;EAAY;CAGvC,MAAM,mCAAmB,IAAI,KAAqB;AAElD,MAAK,MAAM,CAAC,WAAW,gBAAgB,OAAO,QAAQ,SAAS,EAAE;AAC/D,MAAI,eAAe,IAAI,UAAU,CAC/B;EAGF,MAAM,gBAAgB,cAAc,YAAY,GAAG,cAAc;EACjE,MAAM,cACJ,OAAO,eAAe,SAAS,YAAY,cAAc,KAAK,SAAS,IACnE,cAAc,OACd;EAEN,MAAM,aAAa,uBAAuB,YAAY;EACtD,MAAM,gBAAgB,2BAA2B,YAAY,cAAc;EAE3E,MAAM,iBAAiB,YAAY,YAAY,IAAI,YAAY,UAAU,IAAI;EAC7E,MAAM,cAAc,iBAAiB,IAAI,eAAe,IAAI;AAC5D,mBAAiB,IAAI,gBAAgB,cAAc,EAAE;EACrD,MAAM,aAAa,gBAAgB,IAAI,iBAAiB,GAAG,eAAe,GAAG;AAE7E,iBAAe,IAAI,WAAW,cAAc;AAC5C,aAAW,IAAI,WAAW;GAAE;GAAY;GAAY,CAAC;;AAGvD,QAAO;EAAE;EAAgB;EAAY;;AAGvC,SAAS,2BAA2B,UAAkB,eAAoC;AACxF,KAAI,CAAC,cAAc,IAAI,SAAS,EAAE;AAChC,gBAAc,IAAI,SAAS;AAC3B,SAAO;;CAGT,IAAI,QAAQ;AACZ,QAAO,cAAc,IAAI,GAAG,WAAW,QAAQ,CAC7C,UAAS;CAGX,MAAM,aAAa,GAAG,WAAW;AACjC,eAAc,IAAI,WAAW;AAC7B,QAAO"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isPlainObject } from "../utils/shared.js";
|
|
2
|
+
import { formatTemplate } from "../utils/templates.js";
|
|
3
|
+
import { codePropertyAccess, codeReference, createReferenceGetterValue } from "../utils/code-values.js";
|
|
4
|
+
import { buildComponentFileName, toCamelCase, toTriggerReferenceName } from "../utils/naming.js";
|
|
5
|
+
import { addValueToObject } from "../utils/factory-writer.js";
|
|
6
|
+
import "../utils/index.js";
|
|
7
|
+
import { asRecord, collectTemplateVariablesFromValues } from "../collector-common.js";
|
|
8
|
+
import { collectContextTemplateReferences, collectSubAgentReferenceOverrides, collectSubAgentReferencePathOverrides } from "../collector-reference-helpers.js";
|
|
9
|
+
import { addResolvedReferenceImports, resolveReferenceBinding, resolveReferenceBindingsFromIds, toReferenceNameMap } from "../reference-resolution.js";
|
|
10
|
+
import { generateFactorySourceFile } from "../simple-factory-generator.js";
|
|
11
|
+
import { addScheduledTriggerImports, addStatusComponentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createTriggerReferenceMaps, extractIds } from "./helpers/agent.js";
|
|
3
12
|
import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
|
|
4
13
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
14
|
+
import { join } from "node:path";
|
|
6
15
|
|
|
7
16
|
//#region src/commands/pull-v4/generators/agent-generator.ts
|
|
8
17
|
const SubAgentReferenceSchema = z.object({
|
|
@@ -35,60 +44,101 @@ const AgentSchema = z.strictObject({
|
|
|
35
44
|
subAgentReferencePathOverrides: z.record(z.string(), z.string().nonempty()).optional(),
|
|
36
45
|
contextConfigReference: SubAgentReferenceSchema.optional(),
|
|
37
46
|
contextConfigHeadersReference: SubAgentReferenceSchema.optional()
|
|
38
|
-
})
|
|
47
|
+
}).transform((data) => ({
|
|
48
|
+
...data,
|
|
49
|
+
normalizedContextConfigId: normalizeContextConfigId(data.contextConfig),
|
|
50
|
+
normalizedStatusComponentIds: normalizeStatusComponentIds(data.statusUpdates?.statusComponents),
|
|
51
|
+
normalizedStatusComponentSequence: normalizeStatusComponentSequence(data.statusUpdates?.statusComponents)
|
|
52
|
+
}));
|
|
53
|
+
function normalizeContextConfigId(contextConfig) {
|
|
54
|
+
if (typeof contextConfig === "string") return contextConfig;
|
|
55
|
+
if (isPlainObject(contextConfig) && typeof contextConfig.id === "string") return contextConfig.id;
|
|
56
|
+
}
|
|
57
|
+
function normalizeStatusComponentId(statusComponent) {
|
|
58
|
+
if (typeof statusComponent === "string") return statusComponent;
|
|
59
|
+
if (!isPlainObject(statusComponent)) return;
|
|
60
|
+
if (typeof statusComponent.id === "string") return statusComponent.id;
|
|
61
|
+
if (typeof statusComponent.type === "string") return statusComponent.type;
|
|
62
|
+
}
|
|
63
|
+
function normalizeStatusComponentSequence(statusComponents) {
|
|
64
|
+
if (!Array.isArray(statusComponents)) return [];
|
|
65
|
+
return statusComponents.map((statusComponent) => normalizeStatusComponentId(statusComponent)).filter((statusComponentId) => Boolean(statusComponentId));
|
|
66
|
+
}
|
|
67
|
+
function normalizeStatusComponentIds(statusComponents) {
|
|
68
|
+
return [...new Set(normalizeStatusComponentSequence(statusComponents))];
|
|
69
|
+
}
|
|
39
70
|
function generateAgentDefinition({ id, createdAt, updatedAt, ...data }) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
return generateFactorySourceFile(data, {
|
|
72
|
+
schema: AgentSchema,
|
|
73
|
+
factory: {
|
|
74
|
+
importName: "agent",
|
|
75
|
+
variableName: (parsed) => parsed.agentVariableName || toCamelCase(parsed.agentId)
|
|
76
|
+
},
|
|
77
|
+
render({ parsed, sourceFile, configObject }) {
|
|
78
|
+
const subAgentIds = new Set(extractIds(parsed.subAgents));
|
|
79
|
+
if (parsed.defaultSubAgentId) subAgentIds.add(parsed.defaultSubAgentId);
|
|
80
|
+
const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);
|
|
81
|
+
const reservedReferenceNames = new Set([agentVarName]);
|
|
82
|
+
const subAgentReferences = resolveReferenceBindingsFromIds({
|
|
83
|
+
ids: subAgentIds,
|
|
84
|
+
reservedNames: reservedReferenceNames,
|
|
85
|
+
conflictSuffix: "SubAgent",
|
|
86
|
+
referenceOverrides: parsed.subAgentReferences,
|
|
87
|
+
referencePathOverrides: parsed.subAgentReferencePathOverrides,
|
|
88
|
+
defaultModulePath: (id$1) => id$1
|
|
89
|
+
});
|
|
90
|
+
const subAgentReferenceNames = toReferenceNameMap(subAgentReferences);
|
|
91
|
+
addResolvedReferenceImports(sourceFile, subAgentReferences, (reference) => {
|
|
92
|
+
return `./sub-agents/${reference.modulePath}`;
|
|
93
|
+
});
|
|
94
|
+
const contextConfigId = parsed.normalizedContextConfigId;
|
|
95
|
+
let contextConfigReferenceName;
|
|
96
|
+
let contextHeadersReferenceName;
|
|
97
|
+
const hasHeadersTemplateVariables = collectTemplateVariablesFromValues([parsed.prompt, parsed.statusUpdates?.prompt]).some((variableName) => variableName.startsWith("headers."));
|
|
98
|
+
if (contextConfigId) {
|
|
99
|
+
const contextConfigReference = resolveReferenceBinding({
|
|
100
|
+
id: `${contextConfigId}:context`,
|
|
101
|
+
importName: parsed.contextConfigReference?.name ?? toCamelCase(contextConfigId),
|
|
102
|
+
modulePath: contextConfigId,
|
|
103
|
+
local: parsed.contextConfigReference?.local === true,
|
|
104
|
+
conflictSuffix: "ContextConfig"
|
|
105
|
+
}, { reservedNames: reservedReferenceNames });
|
|
106
|
+
contextConfigReferenceName = contextConfigReference.localName;
|
|
107
|
+
const contextReferences = [contextConfigReference];
|
|
108
|
+
if (hasHeadersTemplateVariables) {
|
|
109
|
+
const headersReference = resolveReferenceBinding({
|
|
110
|
+
id: `${contextConfigId}:headers`,
|
|
111
|
+
importName: parsed.contextConfigHeadersReference?.name ?? `${toCamelCase(contextConfigId)}Headers`,
|
|
112
|
+
modulePath: contextConfigId,
|
|
113
|
+
local: parsed.contextConfigHeadersReference?.local === true,
|
|
114
|
+
conflictSuffix: "Headers"
|
|
115
|
+
}, { reservedNames: reservedReferenceNames });
|
|
116
|
+
contextHeadersReferenceName = headersReference.localName;
|
|
117
|
+
contextReferences.push(headersReference);
|
|
118
|
+
}
|
|
119
|
+
addResolvedReferenceImports(sourceFile, contextReferences, () => {
|
|
120
|
+
return `../context-configs/${contextConfigId}`;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } = createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);
|
|
124
|
+
addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);
|
|
125
|
+
const { referenceNames: scheduledTriggerReferenceNames, importRefs: scheduledTriggerImportRefs } = createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);
|
|
126
|
+
addScheduledTriggerImports(sourceFile, scheduledTriggerReferenceNames, scheduledTriggerImportRefs);
|
|
127
|
+
const statusComponentReferenceNames = createReferenceNameMap(parsed.normalizedStatusComponentIds, reservedReferenceNames, "StatusComponent");
|
|
128
|
+
addStatusComponentImports(sourceFile, statusComponentReferenceNames);
|
|
129
|
+
writeAgentConfig(configObject, parsed, {
|
|
130
|
+
subAgents: subAgentReferenceNames,
|
|
131
|
+
contextConfig: contextConfigReferenceName,
|
|
132
|
+
contextHeaders: contextHeadersReferenceName,
|
|
133
|
+
triggers: triggerReferenceNames,
|
|
134
|
+
scheduledTriggers: scheduledTriggerReferenceNames,
|
|
135
|
+
statusComponents: statusComponentReferenceNames
|
|
136
|
+
});
|
|
137
|
+
}
|
|
49
138
|
});
|
|
50
|
-
const reservedReferenceNames = new Set([agentVarName]);
|
|
51
|
-
const { referenceNames: subAgentReferenceNames, importNames: subAgentImportNames } = createSubAgentReferenceMaps(subAgentIds, reservedReferenceNames, "SubAgent", parsed.subAgentReferences);
|
|
52
|
-
addSubAgentImports(sourceFile, subAgentReferenceNames, subAgentImportNames, parsed.subAgentReferencePathOverrides);
|
|
53
|
-
const contextConfigId = extractContextConfigId(parsed.contextConfig);
|
|
54
|
-
let contextConfigReferenceName;
|
|
55
|
-
let contextHeadersReferenceName;
|
|
56
|
-
const hasHeadersTemplateVariables = collectTemplateVariableNamesFromFields([parsed.prompt, parsed.statusUpdates?.prompt]).some((variableName) => variableName.startsWith("headers."));
|
|
57
|
-
if (contextConfigId) {
|
|
58
|
-
const contextImportResolution = resolveContextTemplateImports({
|
|
59
|
-
reservedNames: reservedReferenceNames,
|
|
60
|
-
shouldResolveContextReference: true,
|
|
61
|
-
shouldResolveHeadersReference: hasHeadersTemplateVariables,
|
|
62
|
-
contextConfigReference: parsed.contextConfigReference,
|
|
63
|
-
contextConfigHeadersReference: parsed.contextConfigHeadersReference,
|
|
64
|
-
defaultContextImportName: toCamelCase(contextConfigId),
|
|
65
|
-
defaultHeadersImportName: `${toCamelCase(contextConfigId)}Headers`
|
|
66
|
-
});
|
|
67
|
-
contextConfigReferenceName = contextImportResolution.contextReferenceName;
|
|
68
|
-
contextHeadersReferenceName = contextImportResolution.headersReferenceName;
|
|
69
|
-
if (contextImportResolution.namedImports.length > 0) sourceFile.addImportDeclaration({
|
|
70
|
-
namedImports: contextImportResolution.namedImports,
|
|
71
|
-
moduleSpecifier: `../context-configs/${contextConfigId}`
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } = createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);
|
|
75
|
-
addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);
|
|
76
|
-
const { referenceNames: scheduledTriggerReferenceNames, importRefs: scheduledTriggerImportRefs } = createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);
|
|
77
|
-
addScheduledTriggerImports(sourceFile, scheduledTriggerReferenceNames, scheduledTriggerImportRefs);
|
|
78
|
-
const statusComponentReferenceNames = createReferenceNameMap(extractStatusComponentIds(parsed.statusUpdates), reservedReferenceNames, "StatusComponent");
|
|
79
|
-
addStatusComponentImports(sourceFile, statusComponentReferenceNames);
|
|
80
|
-
writeAgentConfig(configObject, parsed, {
|
|
81
|
-
subAgents: subAgentReferenceNames,
|
|
82
|
-
contextConfig: contextConfigReferenceName,
|
|
83
|
-
contextHeaders: contextHeadersReferenceName,
|
|
84
|
-
triggers: triggerReferenceNames,
|
|
85
|
-
scheduledTriggers: scheduledTriggerReferenceNames,
|
|
86
|
-
statusComponents: statusComponentReferenceNames
|
|
87
|
-
});
|
|
88
|
-
return sourceFile;
|
|
89
139
|
}
|
|
90
140
|
function writeAgentConfig(configObject, data, referenceNames) {
|
|
91
|
-
|
|
141
|
+
const agentConfig = {
|
|
92
142
|
id: data.agentId,
|
|
93
143
|
name: data.name,
|
|
94
144
|
description: data.description,
|
|
@@ -98,40 +148,63 @@ function writeAgentConfig(configObject, data, referenceNames) {
|
|
|
98
148
|
}),
|
|
99
149
|
models: data.models,
|
|
100
150
|
stopWhen: data.stopWhen
|
|
101
|
-
}
|
|
151
|
+
};
|
|
102
152
|
const { defaultSubAgentId } = data;
|
|
103
|
-
if (defaultSubAgentId)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
addReferenceGetterProperty(configObject, "subAgents", extractIds(data.subAgents).map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id)));
|
|
108
|
-
if (extractContextConfigId(data.contextConfig) && referenceNames.contextConfig) configObject.addPropertyAssignment({
|
|
109
|
-
name: "contextConfig",
|
|
110
|
-
initializer: referenceNames.contextConfig
|
|
111
|
-
});
|
|
153
|
+
if (defaultSubAgentId) agentConfig.defaultSubAgent = codeReference(referenceNames.subAgents.get(defaultSubAgentId) ?? toCamelCase(defaultSubAgentId));
|
|
154
|
+
agentConfig.subAgents = createReferenceGetterValue(extractIds(data.subAgents).map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id)));
|
|
155
|
+
if (data.normalizedContextConfigId && referenceNames.contextConfig) agentConfig.contextConfig = codeReference(referenceNames.contextConfig);
|
|
112
156
|
const triggerIds = data.triggers ? extractIds(data.triggers) : [];
|
|
113
|
-
if (triggerIds.length)
|
|
157
|
+
if (triggerIds.length) agentConfig.triggers = createReferenceGetterValue(triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id)));
|
|
114
158
|
const scheduledTriggerIds = data.scheduledTriggers ? extractIds(data.scheduledTriggers) : [];
|
|
115
|
-
if (scheduledTriggerIds.length)
|
|
159
|
+
if (scheduledTriggerIds.length) agentConfig.scheduledTriggers = createReferenceGetterValue(scheduledTriggerIds.map((id) => referenceNames.scheduledTriggers.get(id) ?? toTriggerReferenceName(id)));
|
|
116
160
|
if (data.statusUpdates) {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
const statusComponentRefs = data.statusUpdates.statusComponents?.map((statusComponent) => `${referenceNames.statusComponents.get(resolveStatusComponentId(statusComponent)) ?? toCamelCase(resolveStatusComponentId(statusComponent))}.config`);
|
|
128
|
-
if (statusComponentRefs?.length) statusUpdatesObject.addPropertyAssignment({
|
|
129
|
-
name: "statusComponents",
|
|
130
|
-
initializer: "[]"
|
|
131
|
-
}).getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression).addElements(statusComponentRefs);
|
|
161
|
+
const statusComponentRefs = data.normalizedStatusComponentSequence.map((statusComponentId) => codePropertyAccess(referenceNames.statusComponents.get(statusComponentId) ?? toCamelCase(statusComponentId), "config"));
|
|
162
|
+
agentConfig.statusUpdates = {
|
|
163
|
+
numEvents: data.statusUpdates.numEvents,
|
|
164
|
+
timeInSeconds: data.statusUpdates.timeInSeconds,
|
|
165
|
+
prompt: data.statusUpdates.prompt && formatTemplate(data.statusUpdates.prompt, {
|
|
166
|
+
contextReference: referenceNames.contextConfig,
|
|
167
|
+
headersReference: referenceNames.contextHeaders
|
|
168
|
+
}),
|
|
169
|
+
...statusComponentRefs?.length && { statusComponents: statusComponentRefs }
|
|
170
|
+
};
|
|
132
171
|
}
|
|
172
|
+
for (const [key, value] of Object.entries(agentConfig)) addValueToObject(configObject, key, value);
|
|
133
173
|
}
|
|
174
|
+
const task = {
|
|
175
|
+
type: "agent",
|
|
176
|
+
collect(context) {
|
|
177
|
+
if (!context.project.agents) return [];
|
|
178
|
+
const records = [];
|
|
179
|
+
for (const agentId of context.completeAgentIds) {
|
|
180
|
+
const agentData = context.project.agents[agentId];
|
|
181
|
+
if (!agentData) continue;
|
|
182
|
+
const agentName = typeof agentData.name === "string" ? agentData.name : void 0;
|
|
183
|
+
const agentFilePath = context.resolver.resolveOutputFilePath("agents", agentId, join(context.paths.agentsDir, buildComponentFileName(agentId, agentName)));
|
|
184
|
+
const existingAgent = context.resolver.getExistingComponent(agentId, "agents");
|
|
185
|
+
const subAgentReferences = collectSubAgentReferenceOverrides(context, agentData, agentFilePath);
|
|
186
|
+
const subAgentReferencePathOverrides = collectSubAgentReferencePathOverrides(context, agentData);
|
|
187
|
+
const statusUpdates = asRecord(agentData.statusUpdates);
|
|
188
|
+
const contextTemplateReferences = collectContextTemplateReferences(context, agentData, agentFilePath, [typeof agentData.prompt === "string" ? agentData.prompt : void 0, typeof statusUpdates?.prompt === "string" ? statusUpdates.prompt : void 0]);
|
|
189
|
+
records.push({
|
|
190
|
+
id: agentId,
|
|
191
|
+
filePath: agentFilePath,
|
|
192
|
+
payload: {
|
|
193
|
+
agentId,
|
|
194
|
+
...agentData,
|
|
195
|
+
...existingAgent?.name?.length && { agentVariableName: existingAgent.name },
|
|
196
|
+
...Object.keys(subAgentReferences).length && { subAgentReferences },
|
|
197
|
+
...Object.keys(subAgentReferencePathOverrides).length && { subAgentReferencePathOverrides },
|
|
198
|
+
...contextTemplateReferences && { contextConfigReference: contextTemplateReferences.contextConfigReference },
|
|
199
|
+
...contextTemplateReferences?.contextConfigHeadersReference && { contextConfigHeadersReference: contextTemplateReferences.contextConfigHeadersReference }
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return records;
|
|
204
|
+
},
|
|
205
|
+
generate: generateAgentDefinition
|
|
206
|
+
};
|
|
134
207
|
|
|
135
208
|
//#endregion
|
|
136
|
-
export { generateAgentDefinition };
|
|
209
|
+
export { generateAgentDefinition, task };
|
|
137
210
|
//# sourceMappingURL=agent-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.ts"],"sourcesContent":["import { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport { type ObjectLiteralExpression, type SourceFile, SyntaxKind } from 'ts-morph';\nimport { z } from 'zod';\nimport {\n addReferenceGetterProperty,\n addValueToObject,\n createFactoryDefinition,\n formatTemplate,\n resolveContextTemplateImports,\n toCamelCase,\n toTriggerReferenceName,\n} from '../utils';\nimport {\n addScheduledTriggerImports,\n addStatusComponentImports,\n addSubAgentImports,\n addTriggerImports,\n collectTemplateVariableNamesFromFields,\n createReferenceNameMap,\n createScheduledTriggerReferenceMaps,\n createSubAgentReferenceMaps,\n createTriggerReferenceMaps,\n extractContextConfigId,\n extractIds,\n extractStatusComponentIds,\n type ReferenceNameMap,\n resolveStatusComponentId,\n} from './agent-generator.helpers';\n\nconst SubAgentReferenceSchema = z.object({\n name: z.string().nonempty(),\n local: z.boolean().optional(),\n});\n\nconst MySchema = FullProjectDefinitionSchema.shape.agents.valueType.omit({\n id: true,\n});\n\nconst SubAgentSchema = MySchema.shape.subAgents.valueType.omit({\n // Invalid input: expected \"internal\"\n type: true,\n});\n\nconst ToolSchema = MySchema.shape.tools.unwrap().valueType;\n\nconst AgentSchema = z.strictObject({\n agentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n models: z.preprocess((v) => v ?? undefined, MySchema.shape.models),\n stopWhen: z.preprocess(\n (v) => (v && Object.keys(v).length && v) || undefined,\n MySchema.shape.stopWhen\n ),\n subAgents: z.record(\n z.string(),\n z.strictObject({\n ...SubAgentSchema.shape,\n models: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.models),\n stopWhen: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.stopWhen),\n // Unrecognized keys: \"name\", \"description\", \"content\", \"metadata\", \"subAgentSkillId\", \"subAgentId\", \"createdAt\", \"updatedAt\"\n skills: z.unknown(),\n // Invalid input\n canDelegateTo: z.unknown(),\n })\n ),\n tools: z\n .record(\n z.string(),\n z.strictObject({\n ...ToolSchema.shape,\n // Invalid input: expected string, received null\n imageUrl: z.preprocess((v) => v ?? undefined, ToolSchema.shape.imageUrl),\n })\n )\n .optional(),\n // ✖ Invalid input: expected string, received undefined\n // → at triggers.t546ck7yueh52jils88rm.authentication.headers[0].value\n triggers: z.record(z.string(), z.unknown()).optional(),\n agentVariableName: z.string().nonempty().optional(),\n subAgentReferences: z.record(z.string(), SubAgentReferenceSchema).optional(),\n subAgentReferencePathOverrides: z.record(z.string(), z.string().nonempty()).optional(),\n contextConfigReference: SubAgentReferenceSchema.optional(),\n contextConfigHeadersReference: SubAgentReferenceSchema.optional(),\n});\n\ntype AgentInput = z.input<typeof AgentSchema>;\ntype AgentOutput = z.output<typeof AgentSchema>;\n\ninterface AgentReferenceNames {\n subAgents: ReferenceNameMap;\n contextConfig?: string;\n contextHeaders?: string;\n triggers: ReferenceNameMap;\n scheduledTriggers: ReferenceNameMap;\n statusComponents: ReferenceNameMap;\n}\n\nexport function generateAgentDefinition({\n id,\n createdAt,\n updatedAt,\n ...data\n}: AgentInput & Record<string, unknown>): SourceFile {\n const result = AgentSchema.safeParse(data);\n if (!result.success) {\n throw new Error(`Validation failed for agent:\\n${z.prettifyError(result.error)}`);\n }\n\n const parsed = result.data;\n\n const subAgentIds = new Set(extractIds(parsed.subAgents));\n if (parsed.defaultSubAgentId) {\n subAgentIds.add(parsed.defaultSubAgentId);\n }\n const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);\n const { sourceFile, configObject } = createFactoryDefinition({\n importName: 'agent',\n variableName: agentVarName,\n });\n const reservedReferenceNames = new Set([agentVarName]);\n const { referenceNames: subAgentReferenceNames, importNames: subAgentImportNames } =\n createSubAgentReferenceMaps(\n subAgentIds,\n reservedReferenceNames,\n 'SubAgent',\n parsed.subAgentReferences\n );\n addSubAgentImports(\n sourceFile,\n subAgentReferenceNames,\n subAgentImportNames,\n parsed.subAgentReferencePathOverrides\n );\n\n const contextConfigId = extractContextConfigId(parsed.contextConfig);\n let contextConfigReferenceName: string | undefined;\n let contextHeadersReferenceName: string | undefined;\n const promptTemplateVariables = collectTemplateVariableNamesFromFields([\n parsed.prompt,\n parsed.statusUpdates?.prompt,\n ]);\n const hasHeadersTemplateVariables = promptTemplateVariables.some((variableName) =>\n variableName.startsWith('headers.')\n );\n if (contextConfigId) {\n const contextImportResolution = resolveContextTemplateImports({\n reservedNames: reservedReferenceNames,\n shouldResolveContextReference: true,\n shouldResolveHeadersReference: hasHeadersTemplateVariables,\n contextConfigReference: parsed.contextConfigReference,\n contextConfigHeadersReference: parsed.contextConfigHeadersReference,\n defaultContextImportName: toCamelCase(contextConfigId),\n defaultHeadersImportName: `${toCamelCase(contextConfigId)}Headers`,\n });\n contextConfigReferenceName = contextImportResolution.contextReferenceName;\n contextHeadersReferenceName = contextImportResolution.headersReferenceName;\n\n if (contextImportResolution.namedImports.length > 0) {\n sourceFile.addImportDeclaration({\n namedImports: contextImportResolution.namedImports,\n moduleSpecifier: `../context-configs/${contextConfigId}`,\n });\n }\n }\n\n const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } =\n createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);\n addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);\n\n const { referenceNames: scheduledTriggerReferenceNames, importRefs: scheduledTriggerImportRefs } =\n createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);\n addScheduledTriggerImports(\n sourceFile,\n scheduledTriggerReferenceNames,\n scheduledTriggerImportRefs\n );\n\n const statusComponentReferenceNames = createReferenceNameMap(\n extractStatusComponentIds(parsed.statusUpdates),\n reservedReferenceNames,\n 'StatusComponent'\n );\n addStatusComponentImports(sourceFile, statusComponentReferenceNames);\n\n writeAgentConfig(configObject, parsed, {\n subAgents: subAgentReferenceNames,\n contextConfig: contextConfigReferenceName,\n contextHeaders: contextHeadersReferenceName,\n triggers: triggerReferenceNames,\n scheduledTriggers: scheduledTriggerReferenceNames,\n statusComponents: statusComponentReferenceNames,\n });\n return sourceFile;\n}\n\nfunction writeAgentConfig(\n configObject: ObjectLiteralExpression,\n data: AgentOutput,\n referenceNames: AgentReferenceNames\n) {\n for (const [key, value] of Object.entries({\n id: data.agentId,\n name: data.name,\n description: data.description,\n prompt:\n data.prompt &&\n formatTemplate(data.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n models: data.models,\n stopWhen: data.stopWhen,\n })) {\n addValueToObject(configObject, key, value);\n }\n\n const { defaultSubAgentId } = data;\n if (defaultSubAgentId) {\n configObject.addPropertyAssignment({\n name: 'defaultSubAgent',\n initializer:\n referenceNames.subAgents.get(defaultSubAgentId) ?? toCamelCase(defaultSubAgentId),\n });\n }\n\n const subAgentIds = extractIds(data.subAgents);\n addReferenceGetterProperty(\n configObject,\n 'subAgents',\n subAgentIds.map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id))\n );\n\n const contextConfigId = extractContextConfigId(data.contextConfig);\n if (contextConfigId && referenceNames.contextConfig) {\n configObject.addPropertyAssignment({\n name: 'contextConfig',\n initializer: referenceNames.contextConfig,\n });\n }\n\n const triggerIds = data.triggers ? extractIds(data.triggers) : [];\n if (triggerIds.length) {\n addReferenceGetterProperty(\n configObject,\n 'triggers',\n triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id))\n );\n }\n\n const scheduledTriggerIds = data.scheduledTriggers ? extractIds(data.scheduledTriggers) : [];\n if (scheduledTriggerIds.length) {\n addReferenceGetterProperty(\n configObject,\n 'scheduledTriggers',\n scheduledTriggerIds.map(\n (id) => referenceNames.scheduledTriggers.get(id) ?? toTriggerReferenceName(id)\n )\n );\n }\n\n if (data.statusUpdates) {\n const statusUpdatesProperty = configObject.addPropertyAssignment({\n name: 'statusUpdates',\n initializer: '{}',\n });\n const statusUpdatesObject = statusUpdatesProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ObjectLiteralExpression\n );\n addValueToObject(statusUpdatesObject, 'numEvents', data.statusUpdates.numEvents);\n addValueToObject(statusUpdatesObject, 'timeInSeconds', data.statusUpdates.timeInSeconds);\n addValueToObject(\n statusUpdatesObject,\n 'prompt',\n data.statusUpdates.prompt &&\n formatTemplate(data.statusUpdates.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n })\n );\n const statusComponentRefs = data.statusUpdates.statusComponents?.map(\n (statusComponent) =>\n `${referenceNames.statusComponents.get(resolveStatusComponentId(statusComponent)) ?? toCamelCase(resolveStatusComponentId(statusComponent))}.config`\n );\n if (statusComponentRefs?.length) {\n const statusComponentsProperty = statusUpdatesObject.addPropertyAssignment({\n name: 'statusComponents',\n initializer: '[]',\n });\n const statusComponentsArray = statusComponentsProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ArrayLiteralExpression\n );\n statusComponentsArray.addElements(statusComponentRefs);\n }\n }\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,SAAS,CAAC,UAAU;CAC9B,CAAC;AAEF,MAAM,WAAW,4BAA4B,MAAM,OAAO,UAAU,KAAK,EACvE,IAAI,MACL,CAAC;AAEF,MAAM,iBAAiB,SAAS,MAAM,UAAU,UAAU,KAAK,EAE7D,MAAM,MACP,CAAC;AAEF,MAAM,aAAa,SAAS,MAAM,MAAM,QAAQ,CAAC;AAEjD,MAAM,cAAc,EAAE,aAAa;CACjC,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,GAAG,SAAS;CACZ,aAAa,EAAE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;GACN,aAAa;GACd,CAAC,CACgD,4BAChD,WAAW,wBACZ;AACD,mBAAiB,qBAAqB,aAAa,KAAK,cAAc,UAAU;AAChF,mBAAiB,qBAAqB,iBAAiB,KAAK,cAAc,cAAc;AACxF,mBACE,qBACA,UACA,KAAK,cAAc,UACjB,eAAe,KAAK,cAAc,QAAQ;GACxC,kBAAkB,eAAe;GACjC,kBAAkB,eAAe;GAClC,CAAC,CACL;EACD,MAAM,sBAAsB,KAAK,cAAc,kBAAkB,KAC9D,oBACC,GAAG,eAAe,iBAAiB,IAAI,yBAAyB,gBAAgB,CAAC,IAAI,YAAY,yBAAyB,gBAAgB,CAAC,CAAC,SAC/I;AACD,MAAI,qBAAqB,OAQvB,CAPiC,oBAAoB,sBAAsB;GACzE,MAAM;GACN,aAAa;GACd,CAAC,CACqD,4BACrD,WAAW,uBACZ,CACqB,YAAY,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"agent-generator.js","names":["id"],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { ObjectLiteralExpression, SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { asRecord, collectTemplateVariablesFromValues } from '../collector-common';\nimport {\n collectContextTemplateReferences,\n collectSubAgentReferenceOverrides,\n collectSubAgentReferencePathOverrides,\n} from '../collector-reference-helpers';\nimport type { GenerationTask } from '../generation-types';\nimport {\n addResolvedReferenceImports,\n resolveReferenceBinding,\n resolveReferenceBindingsFromIds,\n toReferenceNameMap,\n} from '../reference-resolution';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\nimport {\n addValueToObject,\n buildComponentFileName,\n codePropertyAccess,\n codeReference,\n createReferenceGetterValue,\n formatTemplate,\n isPlainObject,\n toCamelCase,\n toTriggerReferenceName,\n} from '../utils';\nimport {\n addScheduledTriggerImports,\n addStatusComponentImports,\n addTriggerImports,\n createReferenceNameMap,\n createScheduledTriggerReferenceMaps,\n createTriggerReferenceMaps,\n extractIds,\n type ReferenceNameMap,\n} from './helpers/agent';\n\nconst SubAgentReferenceSchema = z.object({\n name: z.string().nonempty(),\n local: z.boolean().optional(),\n});\n\nconst MySchema = FullProjectDefinitionSchema.shape.agents.valueType.omit({\n id: true,\n});\n\nconst SubAgentSchema = MySchema.shape.subAgents.valueType.omit({\n // Invalid input: expected \"internal\"\n type: true,\n});\n\nconst ToolSchema = MySchema.shape.tools.unwrap().valueType;\n\nconst BaseAgentSchema = z.strictObject({\n agentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n models: z.preprocess((v) => v ?? undefined, MySchema.shape.models),\n stopWhen: z.preprocess(\n (v) => (v && Object.keys(v).length && v) || undefined,\n MySchema.shape.stopWhen\n ),\n subAgents: z.record(\n z.string(),\n z.strictObject({\n ...SubAgentSchema.shape,\n models: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.models),\n stopWhen: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.stopWhen),\n // Unrecognized keys: \"name\", \"description\", \"content\", \"metadata\", \"subAgentSkillId\", \"subAgentId\", \"createdAt\", \"updatedAt\"\n skills: z.unknown(),\n // Invalid input\n canDelegateTo: z.unknown(),\n })\n ),\n tools: z\n .record(\n z.string(),\n z.strictObject({\n ...ToolSchema.shape,\n // Invalid input: expected string, received null\n imageUrl: z.preprocess((v) => v ?? undefined, ToolSchema.shape.imageUrl),\n })\n )\n .optional(),\n // ✖ Invalid input: expected string, received undefined\n // → at triggers.t546ck7yueh52jils88rm.authentication.headers[0].value\n triggers: z.record(z.string(), z.unknown()).optional(),\n agentVariableName: z.string().nonempty().optional(),\n subAgentReferences: z.record(z.string(), SubAgentReferenceSchema).optional(),\n subAgentReferencePathOverrides: z.record(z.string(), z.string().nonempty()).optional(),\n contextConfigReference: SubAgentReferenceSchema.optional(),\n contextConfigHeadersReference: SubAgentReferenceSchema.optional(),\n});\n\nconst AgentSchema = BaseAgentSchema.transform((data) => ({\n ...data,\n normalizedContextConfigId: normalizeContextConfigId(data.contextConfig),\n normalizedStatusComponentIds: normalizeStatusComponentIds(data.statusUpdates?.statusComponents),\n normalizedStatusComponentSequence: normalizeStatusComponentSequence(\n data.statusUpdates?.statusComponents\n ),\n}));\n\ntype AgentInput = z.input<typeof AgentSchema>;\ntype AgentOutput = z.output<typeof AgentSchema>;\n\nfunction normalizeContextConfigId(contextConfig: unknown): string | undefined {\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n\n if (isPlainObject(contextConfig) && typeof contextConfig.id === 'string') {\n return contextConfig.id;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentId(statusComponent: unknown): string | undefined {\n if (typeof statusComponent === 'string') {\n return statusComponent;\n }\n\n if (!isPlainObject(statusComponent)) {\n return undefined;\n }\n\n if (typeof statusComponent.id === 'string') {\n return statusComponent.id;\n }\n\n if (typeof statusComponent.type === 'string') {\n return statusComponent.type;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentSequence(statusComponents: unknown[] | undefined): string[] {\n if (!Array.isArray(statusComponents)) {\n return [];\n }\n\n return statusComponents\n .map((statusComponent) => normalizeStatusComponentId(statusComponent))\n .filter((statusComponentId): statusComponentId is string => Boolean(statusComponentId));\n}\n\nfunction normalizeStatusComponentIds(statusComponents: unknown[] | undefined): string[] {\n return [...new Set(normalizeStatusComponentSequence(statusComponents))];\n}\n\ninterface AgentReferenceNames {\n subAgents: ReferenceNameMap;\n contextConfig?: string;\n contextHeaders?: string;\n triggers: ReferenceNameMap;\n scheduledTriggers: ReferenceNameMap;\n statusComponents: ReferenceNameMap;\n}\n\nexport function generateAgentDefinition({\n id,\n createdAt,\n updatedAt,\n ...data\n}: AgentInput & Record<string, unknown>): SourceFile {\n return generateFactorySourceFile(data, {\n schema: AgentSchema,\n factory: {\n importName: 'agent',\n variableName: (parsed) => parsed.agentVariableName || toCamelCase(parsed.agentId),\n },\n render({ parsed, sourceFile, configObject }) {\n const subAgentIds = new Set(extractIds(parsed.subAgents));\n if (parsed.defaultSubAgentId) {\n subAgentIds.add(parsed.defaultSubAgentId);\n }\n const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);\n const reservedReferenceNames = new Set([agentVarName]);\n const subAgentReferences = resolveReferenceBindingsFromIds({\n ids: subAgentIds,\n reservedNames: reservedReferenceNames,\n conflictSuffix: 'SubAgent',\n referenceOverrides: parsed.subAgentReferences,\n referencePathOverrides: parsed.subAgentReferencePathOverrides,\n defaultModulePath: (id) => id,\n });\n const subAgentReferenceNames = toReferenceNameMap(subAgentReferences);\n addResolvedReferenceImports(sourceFile, subAgentReferences, (reference) => {\n return `./sub-agents/${reference.modulePath}`;\n });\n\n const contextConfigId = parsed.normalizedContextConfigId;\n let contextConfigReferenceName: string | undefined;\n let contextHeadersReferenceName: string | undefined;\n const promptTemplateVariables = collectTemplateVariablesFromValues([\n parsed.prompt,\n parsed.statusUpdates?.prompt,\n ]);\n const hasHeadersTemplateVariables = promptTemplateVariables.some((variableName) =>\n variableName.startsWith('headers.')\n );\n if (contextConfigId) {\n const contextConfigReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:context`,\n importName: parsed.contextConfigReference?.name ?? toCamelCase(contextConfigId),\n modulePath: contextConfigId,\n local: parsed.contextConfigReference?.local === true,\n conflictSuffix: 'ContextConfig',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextConfigReferenceName = contextConfigReference.localName;\n\n const contextReferences = [contextConfigReference];\n if (hasHeadersTemplateVariables) {\n const headersReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:headers`,\n importName:\n parsed.contextConfigHeadersReference?.name ??\n `${toCamelCase(contextConfigId)}Headers`,\n modulePath: contextConfigId,\n local: parsed.contextConfigHeadersReference?.local === true,\n conflictSuffix: 'Headers',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextHeadersReferenceName = headersReference.localName;\n contextReferences.push(headersReference);\n }\n\n addResolvedReferenceImports(sourceFile, contextReferences, () => {\n return `../context-configs/${contextConfigId}`;\n });\n }\n\n const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } =\n createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);\n addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);\n\n const {\n referenceNames: scheduledTriggerReferenceNames,\n importRefs: scheduledTriggerImportRefs,\n } = createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);\n addScheduledTriggerImports(\n sourceFile,\n scheduledTriggerReferenceNames,\n scheduledTriggerImportRefs\n );\n\n const statusComponentReferenceNames = createReferenceNameMap(\n parsed.normalizedStatusComponentIds,\n reservedReferenceNames,\n 'StatusComponent'\n );\n addStatusComponentImports(sourceFile, statusComponentReferenceNames);\n\n writeAgentConfig(configObject, parsed, {\n subAgents: subAgentReferenceNames,\n contextConfig: contextConfigReferenceName,\n contextHeaders: contextHeadersReferenceName,\n triggers: triggerReferenceNames,\n scheduledTriggers: scheduledTriggerReferenceNames,\n statusComponents: statusComponentReferenceNames,\n });\n },\n });\n}\n\nfunction writeAgentConfig(\n configObject: ObjectLiteralExpression,\n data: AgentOutput,\n referenceNames: AgentReferenceNames\n) {\n const agentConfig: Record<string, unknown> = {\n id: data.agentId,\n name: data.name,\n description: data.description,\n prompt:\n data.prompt &&\n formatTemplate(data.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n models: data.models,\n stopWhen: data.stopWhen,\n };\n\n const { defaultSubAgentId } = data;\n if (defaultSubAgentId) {\n agentConfig.defaultSubAgent = codeReference(\n referenceNames.subAgents.get(defaultSubAgentId) ?? toCamelCase(defaultSubAgentId)\n );\n }\n\n const subAgentIds = extractIds(data.subAgents);\n agentConfig.subAgents = createReferenceGetterValue(\n subAgentIds.map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id))\n );\n\n const contextConfigId = data.normalizedContextConfigId;\n if (contextConfigId && referenceNames.contextConfig) {\n agentConfig.contextConfig = codeReference(referenceNames.contextConfig);\n }\n\n const triggerIds = data.triggers ? extractIds(data.triggers) : [];\n if (triggerIds.length) {\n agentConfig.triggers = createReferenceGetterValue(\n triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id))\n );\n }\n\n const scheduledTriggerIds = data.scheduledTriggers ? extractIds(data.scheduledTriggers) : [];\n if (scheduledTriggerIds.length) {\n agentConfig.scheduledTriggers = createReferenceGetterValue(\n scheduledTriggerIds.map(\n (id) => referenceNames.scheduledTriggers.get(id) ?? toTriggerReferenceName(id)\n )\n );\n }\n\n if (data.statusUpdates) {\n const statusComponentRefs = data.normalizedStatusComponentSequence.map((statusComponentId) =>\n codePropertyAccess(\n referenceNames.statusComponents.get(statusComponentId) ?? toCamelCase(statusComponentId),\n 'config'\n )\n );\n agentConfig.statusUpdates = {\n numEvents: data.statusUpdates.numEvents,\n timeInSeconds: data.statusUpdates.timeInSeconds,\n prompt:\n data.statusUpdates.prompt &&\n formatTemplate(data.statusUpdates.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n ...(statusComponentRefs?.length && { statusComponents: statusComponentRefs }),\n };\n }\n\n for (const [key, value] of Object.entries(agentConfig)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nexport const task = {\n type: 'agent',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const records = [];\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n if (!agentData) {\n continue;\n }\n\n const agentName = typeof agentData.name === 'string' ? agentData.name : undefined;\n const agentFilePath = context.resolver.resolveOutputFilePath(\n 'agents',\n agentId,\n join(context.paths.agentsDir, buildComponentFileName(agentId, agentName))\n );\n const existingAgent = context.resolver.getExistingComponent(agentId, 'agents');\n const subAgentReferences = collectSubAgentReferenceOverrides(\n context,\n agentData,\n agentFilePath\n );\n const subAgentReferencePathOverrides = collectSubAgentReferencePathOverrides(\n context,\n agentData\n );\n const statusUpdates = asRecord(agentData.statusUpdates);\n const contextTemplateReferences = collectContextTemplateReferences(\n context,\n agentData,\n agentFilePath,\n [\n typeof agentData.prompt === 'string' ? agentData.prompt : undefined,\n typeof statusUpdates?.prompt === 'string' ? statusUpdates.prompt : undefined,\n ]\n );\n\n records.push({\n id: agentId,\n filePath: agentFilePath,\n payload: {\n agentId,\n ...agentData,\n ...(existingAgent?.name?.length && { agentVariableName: existingAgent.name }),\n ...(Object.keys(subAgentReferences).length && { subAgentReferences }),\n ...(Object.keys(subAgentReferencePathOverrides).length && {\n subAgentReferencePathOverrides,\n }),\n ...(contextTemplateReferences && {\n contextConfigReference: contextTemplateReferences.contextConfigReference,\n }),\n ...(contextTemplateReferences?.contextConfigHeadersReference && {\n contextConfigHeadersReference: contextTemplateReferences.contextConfigHeadersReference,\n }),\n } as Parameters<typeof generateAgentDefinition>[0],\n });\n }\n\n return records;\n },\n generate: generateAgentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateAgentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,SAAS,CAAC,UAAU;CAC9B,CAAC;AAEF,MAAM,WAAW,4BAA4B,MAAM,OAAO,UAAU,KAAK,EACvE,IAAI,MACL,CAAC;AAEF,MAAM,iBAAiB,SAAS,MAAM,UAAU,UAAU,KAAK,EAE7D,MAAM,MACP,CAAC;AAEF,MAAM,aAAa,SAAS,MAAM,MAAM,QAAQ,CAAC;AA2CjD,MAAM,cAzCkB,EAAE,aAAa;CACrC,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,GAAG,SAAS;CACZ,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,YAAY;CAC5E,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,OAAO;CAClE,UAAU,EAAE,YACT,MAAO,KAAK,OAAO,KAAK,EAAE,CAAC,UAAU,KAA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I,CAAC,QAAQ,QAAQ,OACnB,QAAO,EAAE;EAGX,MAAM,UAAU,EAAE;AAClB,OAAK,MAAM,WAAW,QAAQ,kBAAkB;GAC9C,MAAM,YAAY,QAAQ,QAAQ,OAAO;AACzC,OAAI,CAAC,UACH;GAGF,MAAM,YAAY,OAAO,UAAU,SAAS,WAAW,UAAU,OAAO;GACxE,MAAM,gBAAgB,QAAQ,SAAS,sBACrC,UACA,SACA,KAAK,QAAQ,MAAM,WAAW,uBAAuB,SAAS,UAAU,CAAC,CAC1E;GACD,MAAM,gBAAgB,QAAQ,SAAS,qBAAqB,SAAS,SAAS;GAC9E,MAAM,qBAAqB,kCACzB,SACA,WACA,cACD;GACD,MAAM,iCAAiC,sCACrC,SACA,UACD;GACD,MAAM,gBAAgB,SAAS,UAAU,cAAc;GACvD,MAAM,4BAA4B,iCAChC,SACA,WACA,eACA,CACE,OAAO,UAAU,WAAW,WAAW,UAAU,SAAS,QAC1D,OAAO,eAAe,WAAW,WAAW,cAAc,SAAS,OACpE,CACF;AAED,WAAQ,KAAK;IACX,IAAI;IACJ,UAAU;IACV,SAAS;KACP;KACA,GAAG;KACH,GAAI,eAAe,MAAM,UAAU,EAAE,mBAAmB,cAAc,MAAM;KAC5E,GAAI,OAAO,KAAK,mBAAmB,CAAC,UAAU,EAAE,oBAAoB;KACpE,GAAI,OAAO,KAAK,+BAA+B,CAAC,UAAU,EACxD,gCACD;KACD,GAAI,6BAA6B,EAC/B,wBAAwB,0BAA0B,wBACnD;KACD,GAAI,2BAA2B,iCAAiC,EAC9D,+BAA+B,0BAA0B,+BAC1D;KACF;IACF,CAAC;;AAGJ,SAAO;;CAET,UAAU;CACX"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPlainObject } from "../utils/shared.js";
|
|
2
|
+
import { formatPropertyName, formatStringLiteral } from "../utils/templates.js";
|
|
3
|
+
import { codeExpression } from "../utils/code-values.js";
|
|
4
|
+
import { buildComponentFileName, toCamelCase } from "../utils/naming.js";
|
|
5
|
+
import { addValueToObject } from "../utils/factory-writer.js";
|
|
6
|
+
import { convertJsonSchemaToZodSafe } from "../utils/schema-rendering.js";
|
|
7
|
+
import "../utils/index.js";
|
|
8
|
+
import { generateFactorySourceFile } from "../simple-factory-generator.js";
|
|
2
9
|
import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
|
|
3
10
|
import { z } from "zod";
|
|
11
|
+
import { join } from "node:path";
|
|
4
12
|
|
|
5
13
|
//#region src/commands/pull-v4/generators/artifact-component-generator.ts
|
|
6
14
|
const MySchema = FullProjectDefinitionSchema.shape.artifactComponents.unwrap().valueType.omit({ id: true });
|
|
@@ -12,32 +20,30 @@ const ArtifactComponentSchema = z.strictObject({
|
|
|
12
20
|
props: z.unknown()
|
|
13
21
|
});
|
|
14
22
|
function generateArtifactComponentDefinition({ tenantId, id, projectId, createdAt, updatedAt, ...data }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
initializer: formatArtifactSchema(schema)
|
|
23
|
+
return generateFactorySourceFile(data, {
|
|
24
|
+
schema: ArtifactComponentSchema,
|
|
25
|
+
factory: {
|
|
26
|
+
importName: "artifactComponent",
|
|
27
|
+
variableName: (parsed) => toCamelCase(parsed.artifactComponentId)
|
|
28
|
+
},
|
|
29
|
+
render({ parsed, sourceFile, configObject }) {
|
|
30
|
+
const schema = parsed.props;
|
|
31
|
+
if (hasInPreviewFields(schema)) sourceFile.addImportDeclaration({
|
|
32
|
+
namedImports: ["preview"],
|
|
33
|
+
moduleSpecifier: "@inkeep/agents-core"
|
|
34
|
+
});
|
|
35
|
+
if (schema) sourceFile.addImportDeclaration({
|
|
36
|
+
namedImports: ["z"],
|
|
37
|
+
moduleSpecifier: "zod"
|
|
38
|
+
});
|
|
39
|
+
const { artifactComponentId, props: _, ...rest } = parsed;
|
|
40
|
+
for (const [key, value] of Object.entries({
|
|
41
|
+
id: artifactComponentId,
|
|
42
|
+
...rest
|
|
43
|
+
})) addValueToObject(configObject, key, value);
|
|
44
|
+
if (schema) addValueToObject(configObject, "props", codeExpression(formatArtifactSchema(schema)));
|
|
45
|
+
}
|
|
39
46
|
});
|
|
40
|
-
return sourceFile;
|
|
41
47
|
}
|
|
42
48
|
function hasInPreviewFields(schema) {
|
|
43
49
|
if (!isPlainObject(schema) || schema.type !== "object" || !isPlainObject(schema.properties)) return false;
|
|
@@ -60,7 +66,22 @@ function formatArtifactSchema(schema) {
|
|
|
60
66
|
}
|
|
61
67
|
return convertJsonSchemaToZodSafe(schema);
|
|
62
68
|
}
|
|
69
|
+
const task = {
|
|
70
|
+
type: "artifact-component",
|
|
71
|
+
collect(context) {
|
|
72
|
+
if (!context.project.artifactComponents) return [];
|
|
73
|
+
return Object.entries(context.project.artifactComponents).map(([artifactComponentId, artifactComponentData]) => ({
|
|
74
|
+
id: artifactComponentId,
|
|
75
|
+
filePath: context.resolver.resolveOutputFilePath("artifactComponents", artifactComponentId, join(context.paths.artifactComponentsDir, buildComponentFileName(artifactComponentId, artifactComponentData.name ?? void 0))),
|
|
76
|
+
payload: {
|
|
77
|
+
artifactComponentId,
|
|
78
|
+
...artifactComponentData
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
},
|
|
82
|
+
generate: generateArtifactComponentDefinition
|
|
83
|
+
};
|
|
63
84
|
|
|
64
85
|
//#endregion
|
|
65
|
-
export { generateArtifactComponentDefinition };
|
|
86
|
+
export { generateArtifactComponentDefinition, task };
|
|
66
87
|
//# sourceMappingURL=artifact-component-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifact-component-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/artifact-component-generator.ts"],"sourcesContent":["import { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport {\n addValueToObject,\n
|
|
1
|
+
{"version":3,"file":"artifact-component-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/artifact-component-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport type { GenerationTask } from '../generation-types';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\nimport {\n addValueToObject,\n buildComponentFileName,\n codeExpression,\n convertJsonSchemaToZodSafe,\n formatPropertyName,\n formatStringLiteral,\n isPlainObject,\n toCamelCase,\n} from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.artifactComponents.unwrap().valueType.omit({\n id: true,\n});\n\nconst ArtifactComponentSchema = z.strictObject({\n artifactComponentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n render: z.preprocess((v) => v ?? undefined, MySchema.shape.render),\n // Invalid input\n props: z.unknown(),\n});\n\ntype ArtifactComponentInput = z.input<typeof ArtifactComponentSchema>;\n\nexport function generateArtifactComponentDefinition({\n tenantId,\n id,\n projectId,\n createdAt,\n updatedAt,\n ...data\n}: ArtifactComponentInput & Record<string, unknown>): SourceFile {\n return generateFactorySourceFile(data, {\n schema: ArtifactComponentSchema,\n factory: {\n importName: 'artifactComponent',\n variableName: (parsed) => toCamelCase(parsed.artifactComponentId),\n },\n render({ parsed, sourceFile, configObject }) {\n const schema = parsed.props;\n\n if (hasInPreviewFields(schema)) {\n sourceFile.addImportDeclaration({\n namedImports: ['preview'],\n moduleSpecifier: '@inkeep/agents-core',\n });\n }\n if (schema) {\n sourceFile.addImportDeclaration({ namedImports: ['z'], moduleSpecifier: 'zod' });\n }\n\n const { artifactComponentId, props: _, ...rest } = parsed;\n\n for (const [key, value] of Object.entries({\n id: artifactComponentId,\n ...rest,\n })) {\n addValueToObject(configObject, key, value);\n }\n if (schema) {\n addValueToObject(configObject, 'props', codeExpression(formatArtifactSchema(schema)));\n }\n },\n });\n}\n\nfunction hasInPreviewFields(schema: unknown): boolean {\n if (!isPlainObject(schema) || schema.type !== 'object' || !isPlainObject(schema.properties)) {\n return false;\n }\n\n return Object.values(schema.properties).some(\n (property) => isPlainObject(property) && property.inPreview === true\n );\n}\n\nfunction formatArtifactSchema(schema: unknown): string {\n if (!isPlainObject(schema)) {\n return 'z.any()';\n }\n\n if (schema.type === 'object' && isPlainObject(schema.properties)) {\n const lines = ['z.object({'];\n\n for (const [key, propertySchema] of Object.entries(schema.properties)) {\n const propertyWithoutPreview = isPlainObject(propertySchema)\n ? { ...propertySchema }\n : propertySchema;\n\n if (isPlainObject(propertyWithoutPreview)) {\n delete propertyWithoutPreview.inPreview;\n }\n\n const zodType = convertJsonSchemaToZodSafe(propertyWithoutPreview);\n const propertyValue =\n isPlainObject(propertySchema) && propertySchema.inPreview === true\n ? `preview(${zodType})`\n : zodType;\n\n lines.push(` ${formatPropertyName(key)}: ${propertyValue},`);\n }\n\n lines.push('})');\n\n if (typeof schema.description === 'string') {\n return `${lines.join('\\n')}.describe(${formatStringLiteral(schema.description)})`;\n }\n\n return lines.join('\\n');\n }\n\n return convertJsonSchemaToZodSafe(schema);\n}\n\nexport const task = {\n type: 'artifact-component',\n collect(context) {\n if (!context.project.artifactComponents) {\n return [];\n }\n\n return Object.entries(context.project.artifactComponents).map(\n ([artifactComponentId, artifactComponentData]) => ({\n id: artifactComponentId,\n filePath: context.resolver.resolveOutputFilePath(\n 'artifactComponents',\n artifactComponentId,\n join(\n context.paths.artifactComponentsDir,\n buildComponentFileName(artifactComponentId, artifactComponentData.name ?? undefined)\n )\n ),\n payload: {\n artifactComponentId,\n ...artifactComponentData,\n } as Parameters<typeof generateArtifactComponentDefinition>[0],\n })\n );\n },\n generate: generateArtifactComponentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateArtifactComponentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAM,WAAW,4BAA4B,MAAM,mBAAmB,QAAQ,CAAC,UAAU,KAAK,EAC5F,IAAI,MACL,CAAC;AAEF,MAAM,0BAA0B,EAAE,aAAa;CAC7C,qBAAqB,EAAE,QAAQ,CAAC,UAAU;CAC1C,GAAG,SAAS;CACZ,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,YAAY;CAC5E,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,OAAO;CAElE,OAAO,EAAE,SAAS;CACnB,CAAC;AAIF,SAAgB,oCAAoC,EAClD,UACA,IACA,WACA,WACA,WACA,GAAG,QAC4D;AAC/D,QAAO,0BAA0B,MAAM;EACrC,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,eAAe,WAAW,YAAY,OAAO,oBAAoB;GAClE;EACD,OAAO,EAAE,QAAQ,YAAY,gBAAgB;GAC3C,MAAM,SAAS,OAAO;AAEtB,OAAI,mBAAmB,OAAO,CAC5B,YAAW,qBAAqB;IAC9B,cAAc,CAAC,UAAU;IACzB,iBAAiB;IAClB,CAAC;AAEJ,OAAI,OACF,YAAW,qBAAqB;IAAE,cAAc,CAAC,IAAI;IAAE,iBAAiB;IAAO,CAAC;GAGlF,MAAM,EAAE,qBAAqB,OAAO,GAAG,GAAG,SAAS;AAEnD,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ;IACxC,IAAI;IACJ,GAAG;IACJ,CAAC,CACA,kBAAiB,cAAc,KAAK,MAAM;AAE5C,OAAI,OACF,kBAAiB,cAAc,SAAS,eAAe,qBAAqB,OAAO,CAAC,CAAC;;EAG1F,CAAC;;AAGJ,SAAS,mBAAmB,QAA0B;AACpD,KAAI,CAAC,cAAc,OAAO,IAAI,OAAO,SAAS,YAAY,CAAC,cAAc,O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