@inkeep/agents-cli 0.0.0-dev-20260326201814 → 0.0.0-dev-20260326213425
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.
|
@@ -9,7 +9,7 @@ import { collectContextTemplateReferences, collectSubAgentReferenceOverrides, co
|
|
|
9
9
|
import { addResolvedReferenceImports, resolveReferenceBinding, resolveReferenceBindingsFromIds, toReferenceNameMap } from "../reference-resolution.js";
|
|
10
10
|
import { generateFactorySourceFile } from "../simple-factory-generator.js";
|
|
11
11
|
import { addScheduledTriggerImports, addStatusComponentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createTriggerReferenceMaps, extractIds } from "./helpers/agent.js";
|
|
12
|
-
import {
|
|
12
|
+
import { AgentWithinContextOfProjectSchemaBase } from "@inkeep/agents-core";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
|
|
@@ -18,7 +18,7 @@ const SubAgentReferenceSchema = z.object({
|
|
|
18
18
|
name: z.string().nonempty(),
|
|
19
19
|
local: z.boolean().optional()
|
|
20
20
|
});
|
|
21
|
-
const MySchema =
|
|
21
|
+
const MySchema = AgentWithinContextOfProjectSchemaBase.omit({ id: true });
|
|
22
22
|
const SubAgentSchema = MySchema.shape.subAgents.valueType.omit({ type: true });
|
|
23
23
|
const ToolSchema = MySchema.shape.tools.unwrap().valueType;
|
|
24
24
|
const AgentSchema = z.strictObject({
|
|
@@ -1 +1 @@
|
|
|
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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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
|
+
{"version":3,"file":"agent-generator.js","names":["id"],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { AgentWithinContextOfProjectSchemaBase } 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 = AgentWithinContextOfProjectSchemaBase.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,sCAAsC,KAAK,EAC1D,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,KAAM,QAC5C,SAAS,MAAM,SAChB;CACD,WAAW,EAAE,OACX,EAAE,QAAQ,EACV,EAAE,aAAa;EACb,GAAG,eAAe;EAClB,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,OAAO;EACxE,UAAU,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,SAAS;EAE5E,QAAQ,EAAE,SAAS;EAEnB,eAAe,EAAE,SAAS;EAC3B,CAAC,CACH;CACD,OAAO,EACJ,OACC,EAAE,QAAQ,EACV,EAAE,aAAa;EACb,GAAG,WAAW;EAEd,UAAU,EAAE,YAAY,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AS;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-config-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/context-config-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 {\n applyPromptHeaderTemplateSchema,\n asRecord,\n collectHeaderTemplateVariablesFromAgentPrompts,\n} from '../collector-common';\nimport {\n collectContextConfigCredentialReferenceOverrides,\n collectContextConfigCredentialReferencePathOverrides,\n collectContextConfigHeadersReferenceOverride,\n} from '../collector-reference-helpers';\nimport type { GenerationTask } from '../generation-types';\nimport { addNamedImports, applyImportPlan, createImportPlan } from '../import-plan';\nimport { generateValidatedSourceFile } from '../simple-factory-generator';\nimport {\n addFactoryConfigVariable,\n addValueToObject,\n codeExpression,\n codeReference,\n convertJsonSchemaToZodSafe,\n createInMemoryProject,\n isPlainObject,\n toCamelCase,\n} from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.agents.valueType.shape.contextConfig.unwrap();\n\nconst ReferenceNameByIdSchema = z.record(z.string(), z.string().nonempty());\n\nconst ReferenceOverridesSchema = z.object({\n credentialReferences: ReferenceNameByIdSchema.optional(),\n});\n\nconst ReferencePathOverridesSchema = z.object({\n credentialReferences: ReferenceNameByIdSchema.optional(),\n});\n\ninterface NormalizedContextVariableEntry {\n referenceName: string;\n rawValue: unknown;\n fetchDefinitionData?: Record<string, unknown>;\n}\n\ntype NormalizedContextVariableMap = Record<string, NormalizedContextVariableEntry>;\n\nconst BaseContextConfigSchema = z.strictObject({\n contextConfigId: z.string().nonempty(),\n ...MySchema.shape,\n referenceOverrides: ReferenceOverridesSchema.optional(),\n referencePathOverrides: ReferencePathOverridesSchema.optional(),\n\n // TODO check these fields\n headers: z.string().optional(),\n headersReference: z.string().optional(),\n schema: z.unknown(),\n name: z.string().nullish(),\n trigger: z.unknown(),\n fetchConfig: z.record(z.string(), z.unknown()).optional(),\n defaultValue: z.unknown(),\n responseSchema: z.unknown(),\n});\n\nconst ContextConfigSchema = BaseContextConfigSchema.transform((data) => ({\n ...data,\n normalizedHeadersReference: extractHeadersReference(data.headers),\n normalizedContextVariables: normalizeContextVariables(data.contextVariables),\n}));\n\ntype ContextConfigInput = z.input<typeof ContextConfigSchema>;\ntype ContextConfigOutput = z.output<typeof ContextConfigSchema>;\n\nfunction normalizeContextVariables(\n contextVariables?: Record<string, unknown>\n): NormalizedContextVariableMap {\n if (!contextVariables) {\n return {};\n }\n\n const normalizedVariables: NormalizedContextVariableMap = {};\n for (const [key, value] of Object.entries(contextVariables)) {\n const referenceName = extractContextVariableReference(key, value);\n if (!referenceName) {\n continue;\n }\n\n normalizedVariables[key] = {\n referenceName,\n rawValue: value,\n ...(isPlainObject(value) && isFetchDefinitionData(value)\n ? { fetchDefinitionData: value }\n : {}),\n };\n }\n\n return normalizedVariables;\n}\n\nexport function generateContextConfigDefinition(data: ContextConfigInput): SourceFile {\n return generateValidatedSourceFile(data, {\n schema: ContextConfigSchema,\n importName: 'contextConfig',\n render(parsed) {\n const project = createInMemoryProject();\n const sourceFile = project.createSourceFile('context-config-definition.ts', '', {\n overwrite: true,\n });\n\n if (isHeadersDefinitionData(parsed)) {\n return generateStandaloneHeadersDefinition(sourceFile, parsed);\n }\n\n if (isFetchDefinitionData(parsed)) {\n return generateStandaloneFetchDefinition(sourceFile, parsed);\n }\n\n const explicitHeadersReference =\n (typeof parsed.headersReference === 'string' && parsed.headersReference.length > 0\n ? parsed.headersReference\n : undefined) ?? parsed.normalizedHeadersReference;\n const templateHeaderVariables = collectTemplateHeaderVariables(\n parsed.normalizedContextVariables\n );\n const inferredHeadersSchema =\n !isPlainObject(parsed.headersSchema) && !explicitHeadersReference\n ? inferHeadersSchemaFromTemplateHeaderVariables(templateHeaderVariables)\n : undefined;\n const headersSchema = isPlainObject(parsed.headersSchema)\n ? parsed.headersSchema\n : inferredHeadersSchema;\n const headersReference = resolveHeadersReference(parsed, Boolean(headersSchema));\n const shouldDefineHeadersInFile = Boolean(headersReference) && isPlainObject(headersSchema);\n const fetchDefinitions = collectFetchDefinitionEntries(parsed.normalizedContextVariables);\n const credentialReferenceNames = collectCredentialReferenceNames(\n fetchDefinitions,\n parsed.referenceOverrides?.credentialReferences\n );\n const coreImports = ['contextConfig'];\n if (shouldDefineHeadersInFile) {\n coreImports.unshift('headers');\n }\n if (fetchDefinitions.length > 0) {\n coreImports.splice(coreImports.length - 1, 0, 'fetchDefinition');\n }\n\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', coreImports);\n\n const hasResponseSchemas = fetchDefinitions.some((definition) =>\n isPlainObject(definition.data.responseSchema)\n );\n if (shouldDefineHeadersInFile || hasResponseSchemas) {\n addNamedImports(importPlan, 'zod', 'z');\n }\n\n for (const [credentialId, credentialReferenceName] of credentialReferenceNames) {\n const credentialReferencePath =\n parsed.referencePathOverrides?.credentialReferences?.[credentialId] ?? credentialId;\n addNamedImports(\n importPlan,\n `../credentials/${credentialReferencePath}`,\n credentialReferenceName\n );\n }\n applyImportPlan(sourceFile, importPlan);\n if (shouldDefineHeadersInFile && headersReference && headersSchema) {\n const { configObject: headersObject } = addFactoryConfigVariable({\n sourceFile,\n isExported: true,\n importName: 'headers',\n variableName: headersReference,\n });\n\n addValueToObject(headersObject, 'schema', createSchemaExpression(headersSchema));\n }\n\n for (const fetchDefinition of fetchDefinitions) {\n const { configObject: fetchConfigObject } = addFactoryConfigVariable({\n sourceFile,\n importName: 'fetchDefinition',\n variableName: fetchDefinition.variableName,\n });\n writeFetchDefinition(\n fetchConfigObject,\n fetchDefinition.data,\n credentialReferenceNames,\n headersReference\n );\n }\n const contextConfigVarName = toContextConfigVariableName(parsed.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName: 'contextConfig',\n variableName: contextConfigVarName,\n isExported: true,\n });\n\n writeContextConfig(configObject, parsed, headersReference);\n\n return sourceFile;\n },\n });\n}\n\nfunction writeContextConfig(\n configObject: ObjectLiteralExpression,\n data: ContextConfigOutput,\n headersReference?: string\n) {\n const contextConfig: Record<string, unknown> = {};\n if (data.id !== undefined) {\n contextConfig.id = data.id;\n }\n if (headersReference) {\n contextConfig.headers = codeReference(headersReference);\n }\n if (Object.keys(data.normalizedContextVariables).length > 0) {\n const contextVariables: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data.normalizedContextVariables)) {\n contextVariables[key] = codeReference(value.referenceName);\n }\n contextConfig.contextVariables = contextVariables;\n }\n\n for (const [key, value] of Object.entries(contextConfig)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nfunction extractHeadersReference(headers?: string | { id?: string; name?: string }) {\n if (!headers) {\n return undefined;\n }\n if (typeof headers === 'string') {\n return headers;\n }\n if (typeof headers.id === 'string') {\n return headers.id;\n }\n if (typeof headers.name === 'string') {\n return headers.name;\n }\n return undefined;\n}\n\nfunction resolveHeadersReference(\n data: ContextConfigOutput,\n hasHeadersSchema: boolean\n): string | undefined {\n if (typeof data.headersReference === 'string' && data.headersReference) {\n return data.headersReference;\n }\n\n const headersRef = extractHeadersReference(data.headers);\n if (headersRef) {\n return toReferenceIdentifier(headersRef);\n }\n\n if (hasHeadersSchema) {\n return `${toContextConfigVariableName(data.contextConfigId)}Headers`;\n }\n\n return undefined;\n}\n\nfunction isFetchDefinitionData(value: unknown): boolean {\n if (!isPlainObject(value)) {\n return false;\n }\n\n return value.fetchConfig !== undefined || value.responseSchema !== undefined;\n}\n\nfunction collectFetchDefinitionEntries(\n contextVariables?: NormalizedContextVariableMap\n): Array<{ key: string; variableName: string; data: Record<string, unknown> }> {\n if (!contextVariables || Object.keys(contextVariables).length === 0) {\n return [];\n }\n\n return Object.entries(contextVariables)\n .filter(([, value]) => Boolean(value.fetchDefinitionData))\n .map(([key, value]) => ({\n key,\n variableName: value.referenceName,\n data: value.fetchDefinitionData as Record<string, unknown>,\n }));\n}\n\nfunction writeFetchDefinition(\n configObject: ObjectLiteralExpression,\n fetchDefinitionData: unknown,\n credentialReferenceNames?: Map<string, string>,\n headersReference?: string\n) {\n const {\n contextConfigId,\n responseSchema,\n credentialReferenceId,\n normalizedHeadersReference: _normalizedHeadersReference,\n normalizedContextVariables: _normalizedContextVariables,\n ...rest\n } = isPlainObject(fetchDefinitionData) ? fetchDefinitionData : {};\n const normalizedRest = rewriteHeaderTemplates(rest, headersReference);\n const fetchDefinition: Record<string, unknown> = {};\n for (const [k, v] of Object.entries({\n id: contextConfigId,\n ...normalizedRest,\n })) {\n if (v !== null) {\n fetchDefinition[k] = v;\n }\n }\n if (responseSchema) {\n fetchDefinition.responseSchema = createSchemaExpression(\n responseSchema as Record<string, unknown>\n );\n }\n\n if (\n typeof credentialReferenceId === 'string' &&\n credentialReferenceNames?.has(credentialReferenceId)\n ) {\n fetchDefinition.credentialReference = codeReference(\n credentialReferenceNames.get(credentialReferenceId) as string\n );\n } else if (typeof credentialReferenceId === 'string') {\n fetchDefinition.credentialReferenceId = credentialReferenceId;\n }\n\n for (const [key, value] of Object.entries(fetchDefinition)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nconst HEADER_TEMPLATE_REGEX = /\\{\\{headers\\.([^}]+)\\}\\}/g;\nconst HEADER_TO_TEMPLATE_CALL_REGEX =\n /\\$\\{\\s*(headersSchema|headers)\\.toTemplate\\((['\"])([^'\"`]+)\\2\\)\\s*\\}/g;\n\nfunction rewriteHeaderTemplates<T>(value: T, headersReference?: string): T {\n if (!headersReference) {\n return value;\n }\n\n if (typeof value === 'string') {\n const withHeaderTokensReplaced = value.replace(\n HEADER_TEMPLATE_REGEX,\n (_, variableName: string) => {\n return `\\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;\n }\n );\n return withHeaderTokensReplaced.replace(\n HEADER_TO_TEMPLATE_CALL_REGEX,\n (_, __: string, ___: string, variableName: string) => {\n return `\\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;\n }\n ) as T;\n }\n\n if (Array.isArray(value)) {\n return value.map((entry) => rewriteHeaderTemplates(entry, headersReference)) as T;\n }\n\n if (isPlainObject(value)) {\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n key,\n rewriteHeaderTemplates(entryValue, headersReference),\n ])\n ) as T;\n }\n\n return value;\n}\n\nfunction generateStandaloneHeadersDefinition(\n sourceFile: SourceFile,\n data: ContextConfigOutput & { schema: Record<string, unknown> }\n): SourceFile {\n const importName = 'headers';\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', importName);\n addNamedImports(importPlan, 'zod', 'z');\n applyImportPlan(sourceFile, importPlan);\n\n const headersVarName = toContextConfigVariableName(data.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName,\n variableName: headersVarName,\n });\n\n addValueToObject(configObject, 'schema', createSchemaExpression(data.schema));\n return sourceFile;\n}\n\nfunction isHeadersDefinitionData(\n value: ContextConfigOutput\n): value is ContextConfigOutput & { schema: Record<string, unknown> } {\n return isPlainObject(value.schema);\n}\n\nfunction generateStandaloneFetchDefinition(\n sourceFile: SourceFile,\n data: ContextConfigOutput\n): SourceFile {\n const importName = 'fetchDefinition';\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', importName);\n\n if (isPlainObject(data.responseSchema)) {\n addNamedImports(importPlan, 'zod', 'z');\n }\n\n const credentialReferenceNames = new Map<string, string>();\n if (typeof (data as Record<string, unknown>).credentialReferenceId === 'string') {\n const credentialReferenceId = (data as Record<string, unknown>).credentialReferenceId as string;\n const credentialReferenceName =\n data.referenceOverrides?.credentialReferences?.[credentialReferenceId] ??\n toReferenceIdentifier(credentialReferenceId);\n const credentialReferencePath =\n data.referencePathOverrides?.credentialReferences?.[credentialReferenceId] ??\n credentialReferenceId;\n credentialReferenceNames.set(credentialReferenceId, credentialReferenceName);\n addNamedImports(\n importPlan,\n `../credentials/${credentialReferencePath}`,\n credentialReferenceName\n );\n }\n applyImportPlan(sourceFile, importPlan);\n\n const fetchVarName = toContextConfigVariableName(data.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName,\n variableName: fetchVarName,\n });\n\n writeFetchDefinition(configObject, data, credentialReferenceNames);\n return sourceFile;\n}\n\nfunction convertJsonSchemaToZod(schema: Record<string, unknown>): string {\n return convertJsonSchemaToZodSafe(schema, {\n conversionOptions: { module: 'none' },\n });\n}\n\nfunction createSchemaExpression(schema: Record<string, unknown>) {\n return codeExpression(convertJsonSchemaToZod(schema));\n}\n\nfunction extractContextVariableReference(key: string, value: unknown): string | undefined {\n if (typeof value === 'string') {\n return toReferenceIdentifier(value);\n }\n\n if (!isPlainObject(value)) {\n return;\n }\n\n if (typeof value.id === 'string') {\n return toReferenceIdentifier(value.id);\n }\n if (typeof value.name === 'string') {\n return toReferenceIdentifier(value.name);\n }\n if (typeof value.ref === 'string') {\n return toReferenceIdentifier(value.ref);\n }\n if (typeof value.variable === 'string') {\n return toReferenceIdentifier(value.variable);\n }\n\n if (value.fetchConfig || value.responseSchema) {\n return toReferenceIdentifier(key);\n }\n\n return toReferenceIdentifier(key);\n}\n\nconst toContextConfigVariableName = toCamelCase;\n\nconst toReferenceIdentifier = toCamelCase;\n\nfunction collectCredentialReferenceNames(\n fetchDefinitions: Array<{ data: unknown }>,\n overrideNamesById?: Record<string, string>\n): Map<string, string> {\n const credentialReferenceNames = new Map<string, string>();\n\n for (const fetchDefinition of fetchDefinitions) {\n const fetchDefinitionData = isPlainObject(fetchDefinition.data)\n ? fetchDefinition.data\n : undefined;\n const credentialReferenceId =\n fetchDefinitionData && typeof fetchDefinitionData.credentialReferenceId === 'string'\n ? fetchDefinitionData.credentialReferenceId\n : undefined;\n if (!credentialReferenceId || credentialReferenceNames.has(credentialReferenceId)) {\n continue;\n }\n\n credentialReferenceNames.set(\n credentialReferenceId,\n overrideNamesById?.[credentialReferenceId] ?? toReferenceIdentifier(credentialReferenceId)\n );\n }\n\n return credentialReferenceNames;\n}\n\nfunction collectTemplateHeaderVariables(\n contextVariables?: NormalizedContextVariableMap\n): Set<string> {\n const variables = new Set<string>();\n for (const value of Object.values(contextVariables ?? {})) {\n collectTemplateHeaderVariablesFromValue(value.rawValue, variables);\n }\n return variables;\n}\n\nfunction collectTemplateHeaderVariablesFromValue(value: unknown, variables: Set<string>): void {\n if (typeof value === 'string') {\n for (const match of value.matchAll(HEADER_TEMPLATE_REGEX)) {\n if (match[1]) {\n variables.add(match[1]);\n }\n }\n for (const match of value.matchAll(HEADER_TO_TEMPLATE_CALL_REGEX)) {\n if (match[3]) {\n variables.add(match[3]);\n }\n }\n return;\n }\n\n if (Array.isArray(value)) {\n for (const entry of value) {\n collectTemplateHeaderVariablesFromValue(entry, variables);\n }\n return;\n }\n\n if (isPlainObject(value)) {\n for (const entryValue of Object.values(value)) {\n collectTemplateHeaderVariablesFromValue(entryValue, variables);\n }\n }\n}\n\nfunction inferHeadersSchemaFromTemplateHeaderVariables(\n variables: Set<string>\n): Record<string, unknown> | undefined {\n if (!variables.size) {\n return;\n }\n\n const properties: Record<string, unknown> = {};\n for (const variable of [...variables].sort()) {\n properties[variable] = { type: 'string' };\n }\n\n return {\n type: 'object',\n properties,\n required: [...variables].sort(),\n additionalProperties: false,\n };\n}\n\nexport const task = {\n type: 'context-config',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const contextConfigRecordsById = new Map<\n string,\n ReturnType<\n GenerationTask<Parameters<typeof generateContextConfigDefinition>[0]>['collect']\n >[number]\n >();\n\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n const contextConfig = agentData ? asRecord(agentData.contextConfig) : undefined;\n if (!agentData || !contextConfig) {\n continue;\n }\n\n const normalizedContextConfig = applyPromptHeaderTemplateSchema(\n contextConfig,\n collectHeaderTemplateVariablesFromAgentPrompts(agentData)\n );\n const contextConfigId =\n typeof normalizedContextConfig.id === 'string' ? normalizedContextConfig.id : '';\n if (!contextConfigId || contextConfigRecordsById.has(contextConfigId)) {\n continue;\n }\n\n const contextConfigFilePath = context.resolver.resolveOutputFilePath(\n 'contextConfigs',\n contextConfigId,\n join(context.paths.contextConfigsDir, `${contextConfigId}.ts`)\n );\n const credentialReferenceOverrides = collectContextConfigCredentialReferenceOverrides(\n context,\n normalizedContextConfig\n );\n const credentialReferencePathOverrides = collectContextConfigCredentialReferencePathOverrides(\n context,\n normalizedContextConfig\n );\n const headersReferenceOverride = collectContextConfigHeadersReferenceOverride(\n context,\n contextConfigId,\n contextConfigFilePath\n );\n\n contextConfigRecordsById.set(contextConfigId, {\n id: contextConfigId,\n filePath: contextConfigFilePath,\n payload: {\n contextConfigId,\n ...normalizedContextConfig,\n ...(headersReferenceOverride && {\n headersReference: headersReferenceOverride,\n }),\n ...(credentialReferenceOverrides && {\n referenceOverrides: {\n credentialReferences: credentialReferenceOverrides,\n },\n }),\n ...(credentialReferencePathOverrides && {\n referencePathOverrides: {\n credentialReferences: credentialReferencePathOverrides,\n },\n }),\n } as Parameters<typeof generateContextConfigDefinition>[0],\n });\n }\n\n return [...contextConfigRecordsById.values()];\n },\n generate: generateContextConfigDefinition,\n} satisfies GenerationTask<Parameters<typeof generateContextConfigDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAM,WAAW,4BAA4B,MAAM,OAAO,UAAU,MAAM,cAAc,QAAQ;AAEhG,MAAM,0BAA0B,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,UAAU,CAAC;AAE3E,MAAM,2BAA2B,EAAE,OAAO,EACxC,sBAAsB,wBAAwB,UAAU,EACzD,CAAC;AAEF,MAAM,+BAA+B,EAAE,OAAO,EAC5C,sBAAsB,wBAAwB,UAAU,EACzD,CAAC;AA2BF,MAAM,sBAjB0B,EAAE,aAAa;CAC7C,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,GAAG,SAAS;CACZ,oBAAoB,yBAAyB,UAAU;CACvD,wBAAwB,6BAA6B,UAAU;CAG/D,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,kBAAkB,EAAE,QAAQ,CAAC,UAAU;CACvC,QAAQ,EAAE,SAAS;CACnB,MAAM,EAAE,QAAQ,CAAC,SAAS;CAC1B,SAAS,EAAE,SAAS;CACpB,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU;CACzD,cAAc,EAAE,SAAS;CACzB,gBAAgB,EAAE,SAAS;CAC5B,CAAC,CAEkD,WAAW,UAAU;CACvE,GAAG;CACH,4BAA4B,wBAAwB,KAAK,QAAQ;CACjE,4BAA4B,0BAA0B,KAAK,iBAAiB;CAC7E,EAAE;AAKH,SAAS,0BACP,kBAC8B;AAC9B,KAAI,CAAC,iBACH,QAAO,EAAE;CAGX,MAAM,sBAAoD,EAAE;AAC5D,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,iBAAiB,EAAE;EAC3D,MAAM,gBAAgB,gCAAgC,KAAK,MA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,CAAC,GAAG,UAAU,CAAC,MAAM;EAC/B,sBAAsB;EACvB;;AAGH,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;AACf,MAAI,CAAC,QAAQ,QAAQ,OACnB,QAAO,EAAE;EAGX,MAAM,2CAA2B,IAAI,KAKlC;AAEH,OAAK,MAAM,WAAW,QAAQ,kBAAkB;GAC9C,MAAM,YAAY,QAAQ,QAAQ,OAAO;GACzC,MAAM,gBAAgB,YAAY,SAAS,UAAU,cAAc,GAAG;AACtE,OAAI,CAAC,aAAa,CAAC,cACjB;GAGF,MAAM,0BAA0B,gCAC9B,eACA,+CAA+C,UAAU,CAC1D;GACD,MAAM,kBACJ,OAAO,wBAAwB,OAAO,WAAW,wBAAwB,KAAK;AAChF,OAAI,CAAC,mBAAmB,yBAAyB,IAAI,gBAAgB,CACnE;GAGF,MAAM,wBAAwB,QAAQ,SAAS,sBAC7C,kBACA,iBACA,KAAK,QAAQ,MAAM,mBAAmB,GAAG,gBAAgB,KAAK,CAC/D;GACD,MAAM,+BAA+B,iDACnC,SACA,wBACD;GACD,MAAM,mCAAmC,qDACvC,SACA,wBACD;GACD,MAAM,2BAA2B,6CAC/B,SACA,iBACA,sBACD;AAED,4BAAyB,IAAI,iBAAiB;IAC5C,IAAI;IACJ,UAAU;IACV,SAAS;KACP;KACA,GAAG;KACH,GAAI,4BAA4B,EAC9B,kBAAkB,0BACnB;KACD,GAAI,gCAAgC,EAClC,oBAAoB,EAClB,sBAAsB,8BACvB,EACF;KACD,GAAI,oCAAoC,EACtC,wBAAwB,EACtB,sBAAsB,kCACvB,EACF;KACF;IACF,CAAC;;AAGJ,SAAO,CAAC,GAAG,yBAAyB,QAAQ,CAAC;;CAE/C,UAAU;CACX"}
|
|
1
|
+
{"version":3,"file":"context-config-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/context-config-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 {\n applyPromptHeaderTemplateSchema,\n asRecord,\n collectHeaderTemplateVariablesFromAgentPrompts,\n} from '../collector-common';\nimport {\n collectContextConfigCredentialReferenceOverrides,\n collectContextConfigCredentialReferencePathOverrides,\n collectContextConfigHeadersReferenceOverride,\n} from '../collector-reference-helpers';\nimport type { GenerationTask } from '../generation-types';\nimport { addNamedImports, applyImportPlan, createImportPlan } from '../import-plan';\nimport { generateValidatedSourceFile } from '../simple-factory-generator';\nimport {\n addFactoryConfigVariable,\n addValueToObject,\n codeExpression,\n codeReference,\n convertJsonSchemaToZodSafe,\n createInMemoryProject,\n isPlainObject,\n toCamelCase,\n} from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.agents.valueType.shape.contextConfig.unwrap();\n\nconst ReferenceNameByIdSchema = z.record(z.string(), z.string().nonempty());\n\nconst ReferenceOverridesSchema = z.object({\n credentialReferences: ReferenceNameByIdSchema.optional(),\n});\n\nconst ReferencePathOverridesSchema = z.object({\n credentialReferences: ReferenceNameByIdSchema.optional(),\n});\n\ninterface NormalizedContextVariableEntry {\n referenceName: string;\n rawValue: unknown;\n fetchDefinitionData?: Record<string, unknown>;\n}\n\ntype NormalizedContextVariableMap = Record<string, NormalizedContextVariableEntry>;\n\nconst BaseContextConfigSchema = z.strictObject({\n contextConfigId: z.string().nonempty(),\n ...MySchema.shape,\n referenceOverrides: ReferenceOverridesSchema.optional(),\n referencePathOverrides: ReferencePathOverridesSchema.optional(),\n\n // TODO check these fields\n headers: z.string().optional(),\n headersReference: z.string().optional(),\n schema: z.unknown(),\n name: z.string().nullish(),\n trigger: z.unknown(),\n fetchConfig: z.record(z.string(), z.unknown()).optional(),\n defaultValue: z.unknown(),\n responseSchema: z.unknown(),\n});\n\nconst ContextConfigSchema = BaseContextConfigSchema.transform((data) => ({\n ...data,\n normalizedHeadersReference: extractHeadersReference(data.headers),\n normalizedContextVariables: normalizeContextVariables(data.contextVariables),\n}));\n\ntype ContextConfigInput = z.input<typeof ContextConfigSchema>;\ntype ContextConfigOutput = z.output<typeof ContextConfigSchema>;\n\nfunction normalizeContextVariables(\n contextVariables?: Record<string, unknown> | null\n): NormalizedContextVariableMap {\n if (!contextVariables) {\n return {};\n }\n\n const normalizedVariables: NormalizedContextVariableMap = {};\n for (const [key, value] of Object.entries(contextVariables)) {\n const referenceName = extractContextVariableReference(key, value);\n if (!referenceName) {\n continue;\n }\n\n normalizedVariables[key] = {\n referenceName,\n rawValue: value,\n ...(isPlainObject(value) && isFetchDefinitionData(value)\n ? { fetchDefinitionData: value }\n : {}),\n };\n }\n\n return normalizedVariables;\n}\n\nexport function generateContextConfigDefinition(data: ContextConfigInput): SourceFile {\n return generateValidatedSourceFile(data, {\n schema: ContextConfigSchema,\n importName: 'contextConfig',\n render(parsed) {\n const project = createInMemoryProject();\n const sourceFile = project.createSourceFile('context-config-definition.ts', '', {\n overwrite: true,\n });\n\n if (isHeadersDefinitionData(parsed)) {\n return generateStandaloneHeadersDefinition(sourceFile, parsed);\n }\n\n if (isFetchDefinitionData(parsed)) {\n return generateStandaloneFetchDefinition(sourceFile, parsed);\n }\n\n const explicitHeadersReference =\n (typeof parsed.headersReference === 'string' && parsed.headersReference.length > 0\n ? parsed.headersReference\n : undefined) ?? parsed.normalizedHeadersReference;\n const templateHeaderVariables = collectTemplateHeaderVariables(\n parsed.normalizedContextVariables\n );\n const inferredHeadersSchema =\n !isPlainObject(parsed.headersSchema) && !explicitHeadersReference\n ? inferHeadersSchemaFromTemplateHeaderVariables(templateHeaderVariables)\n : undefined;\n const headersSchema = isPlainObject(parsed.headersSchema)\n ? parsed.headersSchema\n : inferredHeadersSchema;\n const headersReference = resolveHeadersReference(parsed, Boolean(headersSchema));\n const shouldDefineHeadersInFile = Boolean(headersReference) && isPlainObject(headersSchema);\n const fetchDefinitions = collectFetchDefinitionEntries(parsed.normalizedContextVariables);\n const credentialReferenceNames = collectCredentialReferenceNames(\n fetchDefinitions,\n parsed.referenceOverrides?.credentialReferences\n );\n const coreImports = ['contextConfig'];\n if (shouldDefineHeadersInFile) {\n coreImports.unshift('headers');\n }\n if (fetchDefinitions.length > 0) {\n coreImports.splice(coreImports.length - 1, 0, 'fetchDefinition');\n }\n\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', coreImports);\n\n const hasResponseSchemas = fetchDefinitions.some((definition) =>\n isPlainObject(definition.data.responseSchema)\n );\n if (shouldDefineHeadersInFile || hasResponseSchemas) {\n addNamedImports(importPlan, 'zod', 'z');\n }\n\n for (const [credentialId, credentialReferenceName] of credentialReferenceNames) {\n const credentialReferencePath =\n parsed.referencePathOverrides?.credentialReferences?.[credentialId] ?? credentialId;\n addNamedImports(\n importPlan,\n `../credentials/${credentialReferencePath}`,\n credentialReferenceName\n );\n }\n applyImportPlan(sourceFile, importPlan);\n if (shouldDefineHeadersInFile && headersReference && headersSchema) {\n const { configObject: headersObject } = addFactoryConfigVariable({\n sourceFile,\n isExported: true,\n importName: 'headers',\n variableName: headersReference,\n });\n\n addValueToObject(headersObject, 'schema', createSchemaExpression(headersSchema));\n }\n\n for (const fetchDefinition of fetchDefinitions) {\n const { configObject: fetchConfigObject } = addFactoryConfigVariable({\n sourceFile,\n importName: 'fetchDefinition',\n variableName: fetchDefinition.variableName,\n });\n writeFetchDefinition(\n fetchConfigObject,\n fetchDefinition.data,\n credentialReferenceNames,\n headersReference\n );\n }\n const contextConfigVarName = toContextConfigVariableName(parsed.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName: 'contextConfig',\n variableName: contextConfigVarName,\n isExported: true,\n });\n\n writeContextConfig(configObject, parsed, headersReference);\n\n return sourceFile;\n },\n });\n}\n\nfunction writeContextConfig(\n configObject: ObjectLiteralExpression,\n data: ContextConfigOutput,\n headersReference?: string\n) {\n const contextConfig: Record<string, unknown> = {};\n if (data.id !== undefined) {\n contextConfig.id = data.id;\n }\n if (headersReference) {\n contextConfig.headers = codeReference(headersReference);\n }\n if (Object.keys(data.normalizedContextVariables).length > 0) {\n const contextVariables: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data.normalizedContextVariables)) {\n contextVariables[key] = codeReference(value.referenceName);\n }\n contextConfig.contextVariables = contextVariables;\n }\n\n for (const [key, value] of Object.entries(contextConfig)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nfunction extractHeadersReference(headers?: string | { id?: string; name?: string }) {\n if (!headers) {\n return undefined;\n }\n if (typeof headers === 'string') {\n return headers;\n }\n if (typeof headers.id === 'string') {\n return headers.id;\n }\n if (typeof headers.name === 'string') {\n return headers.name;\n }\n return undefined;\n}\n\nfunction resolveHeadersReference(\n data: ContextConfigOutput,\n hasHeadersSchema: boolean\n): string | undefined {\n if (typeof data.headersReference === 'string' && data.headersReference) {\n return data.headersReference;\n }\n\n const headersRef = extractHeadersReference(data.headers);\n if (headersRef) {\n return toReferenceIdentifier(headersRef);\n }\n\n if (hasHeadersSchema) {\n return `${toContextConfigVariableName(data.contextConfigId)}Headers`;\n }\n\n return undefined;\n}\n\nfunction isFetchDefinitionData(value: unknown): boolean {\n if (!isPlainObject(value)) {\n return false;\n }\n\n return value.fetchConfig !== undefined || value.responseSchema !== undefined;\n}\n\nfunction collectFetchDefinitionEntries(\n contextVariables?: NormalizedContextVariableMap\n): Array<{ key: string; variableName: string; data: Record<string, unknown> }> {\n if (!contextVariables || Object.keys(contextVariables).length === 0) {\n return [];\n }\n\n return Object.entries(contextVariables)\n .filter(([, value]) => Boolean(value.fetchDefinitionData))\n .map(([key, value]) => ({\n key,\n variableName: value.referenceName,\n data: value.fetchDefinitionData as Record<string, unknown>,\n }));\n}\n\nfunction writeFetchDefinition(\n configObject: ObjectLiteralExpression,\n fetchDefinitionData: unknown,\n credentialReferenceNames?: Map<string, string>,\n headersReference?: string\n) {\n const {\n contextConfigId,\n responseSchema,\n credentialReferenceId,\n normalizedHeadersReference: _normalizedHeadersReference,\n normalizedContextVariables: _normalizedContextVariables,\n ...rest\n } = isPlainObject(fetchDefinitionData) ? fetchDefinitionData : {};\n const normalizedRest = rewriteHeaderTemplates(rest, headersReference);\n const fetchDefinition: Record<string, unknown> = {};\n for (const [k, v] of Object.entries({\n id: contextConfigId,\n ...normalizedRest,\n })) {\n if (v !== null) {\n fetchDefinition[k] = v;\n }\n }\n if (responseSchema) {\n fetchDefinition.responseSchema = createSchemaExpression(\n responseSchema as Record<string, unknown>\n );\n }\n\n if (\n typeof credentialReferenceId === 'string' &&\n credentialReferenceNames?.has(credentialReferenceId)\n ) {\n fetchDefinition.credentialReference = codeReference(\n credentialReferenceNames.get(credentialReferenceId) as string\n );\n } else if (typeof credentialReferenceId === 'string') {\n fetchDefinition.credentialReferenceId = credentialReferenceId;\n }\n\n for (const [key, value] of Object.entries(fetchDefinition)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nconst HEADER_TEMPLATE_REGEX = /\\{\\{headers\\.([^}]+)\\}\\}/g;\nconst HEADER_TO_TEMPLATE_CALL_REGEX =\n /\\$\\{\\s*(headersSchema|headers)\\.toTemplate\\((['\"])([^'\"`]+)\\2\\)\\s*\\}/g;\n\nfunction rewriteHeaderTemplates<T>(value: T, headersReference?: string): T {\n if (!headersReference) {\n return value;\n }\n\n if (typeof value === 'string') {\n const withHeaderTokensReplaced = value.replace(\n HEADER_TEMPLATE_REGEX,\n (_, variableName: string) => {\n return `\\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;\n }\n );\n return withHeaderTokensReplaced.replace(\n HEADER_TO_TEMPLATE_CALL_REGEX,\n (_, __: string, ___: string, variableName: string) => {\n return `\\${${headersReference}.toTemplate(${JSON.stringify(variableName)})}`;\n }\n ) as T;\n }\n\n if (Array.isArray(value)) {\n return value.map((entry) => rewriteHeaderTemplates(entry, headersReference)) as T;\n }\n\n if (isPlainObject(value)) {\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n key,\n rewriteHeaderTemplates(entryValue, headersReference),\n ])\n ) as T;\n }\n\n return value;\n}\n\nfunction generateStandaloneHeadersDefinition(\n sourceFile: SourceFile,\n data: ContextConfigOutput & { schema: Record<string, unknown> }\n): SourceFile {\n const importName = 'headers';\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', importName);\n addNamedImports(importPlan, 'zod', 'z');\n applyImportPlan(sourceFile, importPlan);\n\n const headersVarName = toContextConfigVariableName(data.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName,\n variableName: headersVarName,\n });\n\n addValueToObject(configObject, 'schema', createSchemaExpression(data.schema));\n return sourceFile;\n}\n\nfunction isHeadersDefinitionData(\n value: ContextConfigOutput\n): value is ContextConfigOutput & { schema: Record<string, unknown> } {\n return isPlainObject(value.schema);\n}\n\nfunction generateStandaloneFetchDefinition(\n sourceFile: SourceFile,\n data: ContextConfigOutput\n): SourceFile {\n const importName = 'fetchDefinition';\n const importPlan = createImportPlan();\n addNamedImports(importPlan, '@inkeep/agents-core', importName);\n\n if (isPlainObject(data.responseSchema)) {\n addNamedImports(importPlan, 'zod', 'z');\n }\n\n const credentialReferenceNames = new Map<string, string>();\n if (typeof (data as Record<string, unknown>).credentialReferenceId === 'string') {\n const credentialReferenceId = (data as Record<string, unknown>).credentialReferenceId as string;\n const credentialReferenceName =\n data.referenceOverrides?.credentialReferences?.[credentialReferenceId] ??\n toReferenceIdentifier(credentialReferenceId);\n const credentialReferencePath =\n data.referencePathOverrides?.credentialReferences?.[credentialReferenceId] ??\n credentialReferenceId;\n credentialReferenceNames.set(credentialReferenceId, credentialReferenceName);\n addNamedImports(\n importPlan,\n `../credentials/${credentialReferencePath}`,\n credentialReferenceName\n );\n }\n applyImportPlan(sourceFile, importPlan);\n\n const fetchVarName = toContextConfigVariableName(data.contextConfigId);\n const { configObject } = addFactoryConfigVariable({\n sourceFile,\n importName,\n variableName: fetchVarName,\n });\n\n writeFetchDefinition(configObject, data, credentialReferenceNames);\n return sourceFile;\n}\n\nfunction convertJsonSchemaToZod(schema: Record<string, unknown>): string {\n return convertJsonSchemaToZodSafe(schema, {\n conversionOptions: { module: 'none' },\n });\n}\n\nfunction createSchemaExpression(schema: Record<string, unknown>) {\n return codeExpression(convertJsonSchemaToZod(schema));\n}\n\nfunction extractContextVariableReference(key: string, value: unknown): string | undefined {\n if (typeof value === 'string') {\n return toReferenceIdentifier(value);\n }\n\n if (!isPlainObject(value)) {\n return;\n }\n\n if (typeof value.id === 'string') {\n return toReferenceIdentifier(value.id);\n }\n if (typeof value.name === 'string') {\n return toReferenceIdentifier(value.name);\n }\n if (typeof value.ref === 'string') {\n return toReferenceIdentifier(value.ref);\n }\n if (typeof value.variable === 'string') {\n return toReferenceIdentifier(value.variable);\n }\n\n if (value.fetchConfig || value.responseSchema) {\n return toReferenceIdentifier(key);\n }\n\n return toReferenceIdentifier(key);\n}\n\nconst toContextConfigVariableName = toCamelCase;\n\nconst toReferenceIdentifier = toCamelCase;\n\nfunction collectCredentialReferenceNames(\n fetchDefinitions: Array<{ data: unknown }>,\n overrideNamesById?: Record<string, string>\n): Map<string, string> {\n const credentialReferenceNames = new Map<string, string>();\n\n for (const fetchDefinition of fetchDefinitions) {\n const fetchDefinitionData = isPlainObject(fetchDefinition.data)\n ? fetchDefinition.data\n : undefined;\n const credentialReferenceId =\n fetchDefinitionData && typeof fetchDefinitionData.credentialReferenceId === 'string'\n ? fetchDefinitionData.credentialReferenceId\n : undefined;\n if (!credentialReferenceId || credentialReferenceNames.has(credentialReferenceId)) {\n continue;\n }\n\n credentialReferenceNames.set(\n credentialReferenceId,\n overrideNamesById?.[credentialReferenceId] ?? toReferenceIdentifier(credentialReferenceId)\n );\n }\n\n return credentialReferenceNames;\n}\n\nfunction collectTemplateHeaderVariables(\n contextVariables?: NormalizedContextVariableMap\n): Set<string> {\n const variables = new Set<string>();\n for (const value of Object.values(contextVariables ?? {})) {\n collectTemplateHeaderVariablesFromValue(value.rawValue, variables);\n }\n return variables;\n}\n\nfunction collectTemplateHeaderVariablesFromValue(value: unknown, variables: Set<string>): void {\n if (typeof value === 'string') {\n for (const match of value.matchAll(HEADER_TEMPLATE_REGEX)) {\n if (match[1]) {\n variables.add(match[1]);\n }\n }\n for (const match of value.matchAll(HEADER_TO_TEMPLATE_CALL_REGEX)) {\n if (match[3]) {\n variables.add(match[3]);\n }\n }\n return;\n }\n\n if (Array.isArray(value)) {\n for (const entry of value) {\n collectTemplateHeaderVariablesFromValue(entry, variables);\n }\n return;\n }\n\n if (isPlainObject(value)) {\n for (const entryValue of Object.values(value)) {\n collectTemplateHeaderVariablesFromValue(entryValue, variables);\n }\n }\n}\n\nfunction inferHeadersSchemaFromTemplateHeaderVariables(\n variables: Set<string>\n): Record<string, unknown> | undefined {\n if (!variables.size) {\n return;\n }\n\n const properties: Record<string, unknown> = {};\n for (const variable of [...variables].sort()) {\n properties[variable] = { type: 'string' };\n }\n\n return {\n type: 'object',\n properties,\n required: [...variables].sort(),\n additionalProperties: false,\n };\n}\n\ntype GeneratorParams = Parameters<typeof generateContextConfigDefinition>[0];\n\nexport const task: GenerationTask<GeneratorParams> = {\n type: 'context-config',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const contextConfigRecordsById = new Map<\n string,\n ReturnType<GenerationTask<GeneratorParams>['collect']>[number]\n >();\n\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n const contextConfig = agentData ? asRecord(agentData.contextConfig) : undefined;\n if (!agentData || !contextConfig) {\n continue;\n }\n\n const normalizedContextConfig = applyPromptHeaderTemplateSchema(\n contextConfig,\n collectHeaderTemplateVariablesFromAgentPrompts(agentData)\n );\n const contextConfigId =\n typeof normalizedContextConfig.id === 'string' ? normalizedContextConfig.id : '';\n if (!contextConfigId || contextConfigRecordsById.has(contextConfigId)) {\n continue;\n }\n\n const contextConfigFilePath = context.resolver.resolveOutputFilePath(\n 'contextConfigs',\n contextConfigId,\n join(context.paths.contextConfigsDir, `${contextConfigId}.ts`)\n );\n const credentialReferenceOverrides = collectContextConfigCredentialReferenceOverrides(\n context,\n normalizedContextConfig\n );\n const credentialReferencePathOverrides = collectContextConfigCredentialReferencePathOverrides(\n context,\n normalizedContextConfig\n );\n const headersReferenceOverride = collectContextConfigHeadersReferenceOverride(\n context,\n contextConfigId,\n contextConfigFilePath\n );\n\n contextConfigRecordsById.set(contextConfigId, {\n id: contextConfigId,\n filePath: contextConfigFilePath,\n payload: {\n contextConfigId,\n ...normalizedContextConfig,\n ...(headersReferenceOverride && {\n headersReference: headersReferenceOverride,\n }),\n ...(credentialReferenceOverrides && {\n referenceOverrides: {\n credentialReferences: credentialReferenceOverrides,\n },\n }),\n ...(credentialReferencePathOverrides && {\n referencePathOverrides: {\n credentialReferences: credentialReferencePathOverrides,\n },\n }),\n } as GeneratorParams,\n });\n }\n\n return [...contextConfigRecordsById.values()];\n },\n generate: generateContextConfigDefinition,\n};\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAM,WAAW,4BAA4B,MAAM,OAAO,UAAU,MAAM,cAAc,QAAQ;AAEhG,MAAM,0BAA0B,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,UAAU,CAAC;AAE3E,MAAM,2BAA2B,EAAE,OAAO,EACxC,sBAAsB,wBAAwB,UAAU,EACzD,CAAC;AAEF,MAAM,+BAA+B,EAAE,OAAO,EAC5C,sBAAsB,wBAAwB,UAAU,EACzD,CAAC;AA2BF,MAAM,sBAjB0B,EAAE,aAAa;CAC7C,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,GAAG,SAAS;CACZ,oBAAoB,yBAAyB,UAAU;CACvD,wBAAwB,6BAA6B,UAAU;CAG/D,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,kBAAkB,EAAE,QAAQ,CAAC,UAAU;CACvC,QAAQ,EAAE,SAAS;CACnB,MAAM,EAAE,QAAQ,CAAC,SAAS;CAC1B,SAAS,EAAE,SAAS;CACpB,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,U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9B,kBAAkB,0BACnB;KACD,GAAI,gCAAgC,EAClC,oBAAoB,EAClB,sBAAsB,8BACvB,EACF;KACD,GAAI,oCAAoC,EACtC,wBAAwB,EACtB,sBAAsB,kCACvB,EACF;KACF;IACF,CAAC;;AAGJ,SAAO,CAAC,GAAG,yBAAyB,QAAQ,CAAC;;CAE/C,UAAU;CACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-cli",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260326213425",
|
|
4
4
|
"description": "Inkeep CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"tsx": "^4.20.5",
|
|
38
38
|
"yaml": "^2.7.0",
|
|
39
39
|
"zod": "^4.3.6",
|
|
40
|
-
"@inkeep/agents-core": "^0.0.0-dev-
|
|
41
|
-
"@inkeep/agents-sdk": "^0.0.0-dev-
|
|
40
|
+
"@inkeep/agents-core": "^0.0.0-dev-20260326213425",
|
|
41
|
+
"@inkeep/agents-sdk": "^0.0.0-dev-20260326213425"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"diff": "^8.0.3",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"vitest": "^3.2.4"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@inkeep/agents-manage-ui": "0.0.0-dev-
|
|
53
|
+
"@inkeep/agents-manage-ui": "0.0.0-dev-20260326213425"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public",
|