@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,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { codeExpression } from "../utils/code-values.js";
|
|
2
|
+
import { buildComponentFileName, toCamelCase } from "../utils/naming.js";
|
|
3
|
+
import { addStringProperty, addValueToObject } from "../utils/factory-writer.js";
|
|
4
|
+
import { convertJsonSchemaToZodSafe } from "../utils/schema-rendering.js";
|
|
5
|
+
import "../utils/index.js";
|
|
6
|
+
import { collectReferencedSubAgentComponentIds } from "../collector-common.js";
|
|
7
|
+
import { generateFactorySourceFile } from "../simple-factory-generator.js";
|
|
2
8
|
import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
|
|
3
9
|
import { z } from "zod";
|
|
10
|
+
import { join } from "node:path";
|
|
4
11
|
|
|
5
12
|
//#region src/commands/pull-v4/generators/data-component-generator.ts
|
|
6
13
|
const MySchema = FullProjectDefinitionSchema.shape.dataComponents.unwrap().valueType.omit({ id: true });
|
|
@@ -11,29 +18,27 @@ const DataComponentSchema = z.strictObject({
|
|
|
11
18
|
props: z.unknown()
|
|
12
19
|
});
|
|
13
20
|
function generateDataComponentDefinition({ tenantId, id, projectId, createdAt, updatedAt, ...data }) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
return generateFactorySourceFile(data, {
|
|
22
|
+
schema: DataComponentSchema,
|
|
23
|
+
factory: {
|
|
24
|
+
importName: "dataComponent",
|
|
25
|
+
variableName: (parsed) => toCamelCase(parsed.dataComponentId)
|
|
26
|
+
},
|
|
27
|
+
render({ parsed, sourceFile, configObject }) {
|
|
28
|
+
const props = parsed.props;
|
|
29
|
+
if (props !== void 0) sourceFile.addImportDeclaration({
|
|
30
|
+
namedImports: ["z"],
|
|
31
|
+
moduleSpecifier: "zod"
|
|
32
|
+
});
|
|
33
|
+
writeDataComponentConfig(configObject, parsed, props);
|
|
34
|
+
}
|
|
21
35
|
});
|
|
22
|
-
if (props !== void 0) sourceFile.addImportDeclaration({
|
|
23
|
-
namedImports: ["z"],
|
|
24
|
-
moduleSpecifier: "zod"
|
|
25
|
-
});
|
|
26
|
-
writeDataComponentConfig(configObject, parsed, props);
|
|
27
|
-
return sourceFile;
|
|
28
36
|
}
|
|
29
37
|
function writeDataComponentConfig(configObject, data, props) {
|
|
30
38
|
addStringProperty(configObject, "id", data.dataComponentId);
|
|
31
39
|
addStringProperty(configObject, "name", data.name);
|
|
32
40
|
if (typeof data.description === "string") addStringProperty(configObject, "description", data.description);
|
|
33
|
-
if (props !== void 0) configObject
|
|
34
|
-
name: "props",
|
|
35
|
-
initializer: convertJsonSchemaToZodSafe(props)
|
|
36
|
-
});
|
|
41
|
+
if (props !== void 0) addValueToObject(configObject, "props", codeExpression(convertJsonSchemaToZodSafe(props)));
|
|
37
42
|
if (data.render) addRenderProperty(configObject, data.render);
|
|
38
43
|
}
|
|
39
44
|
function addRenderProperty(configObject, render) {
|
|
@@ -42,7 +47,38 @@ function addRenderProperty(configObject, render) {
|
|
|
42
47
|
mockData: render.mockData
|
|
43
48
|
});
|
|
44
49
|
}
|
|
50
|
+
const task = {
|
|
51
|
+
type: "data-component",
|
|
52
|
+
collect(context) {
|
|
53
|
+
const recordsByDataComponentId = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const [dataComponentId, dataComponent] of Object.entries(context.project.dataComponents ?? {})) recordsByDataComponentId.set(dataComponentId, {
|
|
55
|
+
id: dataComponentId,
|
|
56
|
+
filePath: context.resolver.resolveOutputFilePath("dataComponents", dataComponentId, join(context.paths.dataComponentsDir, buildComponentFileName(dataComponentId, dataComponent.name ?? void 0))),
|
|
57
|
+
payload: {
|
|
58
|
+
dataComponentId,
|
|
59
|
+
...dataComponent
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
for (const dataComponentId of collectReferencedSubAgentComponentIds(context, "dataComponents")) {
|
|
63
|
+
if (recordsByDataComponentId.has(dataComponentId)) continue;
|
|
64
|
+
recordsByDataComponentId.set(dataComponentId, {
|
|
65
|
+
id: dataComponentId,
|
|
66
|
+
filePath: context.resolver.resolveOutputFilePath("dataComponents", dataComponentId, join(context.paths.dataComponentsDir, `${dataComponentId}.ts`)),
|
|
67
|
+
payload: {
|
|
68
|
+
dataComponentId,
|
|
69
|
+
name: dataComponentId,
|
|
70
|
+
props: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return [...recordsByDataComponentId.values()];
|
|
78
|
+
},
|
|
79
|
+
generate: generateDataComponentDefinition
|
|
80
|
+
};
|
|
45
81
|
|
|
46
82
|
//#endregion
|
|
47
|
-
export { generateDataComponentDefinition };
|
|
83
|
+
export { generateDataComponentDefinition, task };
|
|
48
84
|
//# sourceMappingURL=data-component-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-component-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/data-component-generator.ts"],"sourcesContent":["import { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { ObjectLiteralExpression, SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport {\n addStringProperty,\n addValueToObject,\n
|
|
1
|
+
{"version":3,"file":"data-component-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/data-component-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 { collectReferencedSubAgentComponentIds } from '../collector-common';\nimport type { GenerationTask } from '../generation-types';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\nimport {\n addStringProperty,\n addValueToObject,\n buildComponentFileName,\n codeExpression,\n convertJsonSchemaToZodSafe,\n toCamelCase,\n} from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.dataComponents.unwrap().valueType.omit({\n id: true,\n});\n\nconst DataComponentSchema = z.strictObject({\n dataComponentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n // Each property must have a \"description\" for LLM compatibility\n props: z.unknown(),\n});\n\ntype DataComponentInput = z.input<typeof DataComponentSchema>;\ntype DataComponentOutput = z.output<typeof DataComponentSchema>;\n\nexport function generateDataComponentDefinition({\n tenantId,\n id,\n projectId,\n createdAt,\n updatedAt,\n ...data\n}: DataComponentInput & Record<string, unknown>): SourceFile {\n return generateFactorySourceFile(data, {\n schema: DataComponentSchema,\n factory: {\n importName: 'dataComponent',\n variableName: (parsed) => toCamelCase(parsed.dataComponentId),\n },\n render({ parsed, sourceFile, configObject }) {\n const props = parsed.props;\n if (props !== undefined) {\n sourceFile.addImportDeclaration({\n namedImports: ['z'],\n moduleSpecifier: 'zod',\n });\n }\n\n writeDataComponentConfig(configObject, parsed, props);\n },\n });\n}\n\nfunction writeDataComponentConfig(\n configObject: ObjectLiteralExpression,\n data: DataComponentOutput,\n props: unknown\n): void {\n addStringProperty(configObject, 'id', data.dataComponentId);\n addStringProperty(configObject, 'name', data.name);\n\n if (typeof data.description === 'string') {\n addStringProperty(configObject, 'description', data.description);\n }\n\n if (props !== undefined) {\n addValueToObject(configObject, 'props', codeExpression(convertJsonSchemaToZodSafe(props)));\n }\n\n if (data.render) {\n addRenderProperty(configObject, data.render);\n }\n}\n\nfunction addRenderProperty(\n configObject: ObjectLiteralExpression,\n render: NonNullable<DataComponentOutput['render']>\n): void {\n if (render.component) {\n addValueToObject(configObject, 'render', {\n component: render.component,\n mockData: render.mockData,\n });\n }\n}\n\nexport const task = {\n type: 'data-component',\n collect(context) {\n const recordsByDataComponentId = new Map<\n string,\n ReturnType<\n GenerationTask<Parameters<typeof generateDataComponentDefinition>[0]>['collect']\n >[number]\n >();\n\n for (const [dataComponentId, dataComponent] of Object.entries(\n context.project.dataComponents ?? {}\n )) {\n recordsByDataComponentId.set(dataComponentId, {\n id: dataComponentId,\n filePath: context.resolver.resolveOutputFilePath(\n 'dataComponents',\n dataComponentId,\n join(\n context.paths.dataComponentsDir,\n buildComponentFileName(dataComponentId, dataComponent.name ?? undefined)\n )\n ),\n payload: {\n dataComponentId,\n ...dataComponent,\n } as Parameters<typeof generateDataComponentDefinition>[0],\n });\n }\n\n for (const dataComponentId of collectReferencedSubAgentComponentIds(\n context,\n 'dataComponents'\n )) {\n if (recordsByDataComponentId.has(dataComponentId)) {\n continue;\n }\n\n recordsByDataComponentId.set(dataComponentId, {\n id: dataComponentId,\n filePath: context.resolver.resolveOutputFilePath(\n 'dataComponents',\n dataComponentId,\n join(context.paths.dataComponentsDir, `${dataComponentId}.ts`)\n ),\n payload: {\n dataComponentId,\n name: dataComponentId,\n props: { type: 'object', properties: {} },\n } as Parameters<typeof generateDataComponentDefinition>[0],\n });\n }\n\n return [...recordsByDataComponentId.values()];\n },\n generate: generateDataComponentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateDataComponentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,WAAW,4BAA4B,MAAM,eAAe,QAAQ,CAAC,UAAU,KAAK,EACxF,IAAI,MACL,CAAC;AAEF,MAAM,sBAAsB,EAAE,aAAa;CACzC,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,GAAG,SAAS;CACZ,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,YAAY;CAE5E,OAAO,EAAE,SAAS;CACnB,CAAC;AAKF,SAAgB,gCAAgC,EAC9C,UACA,IACA,WACA,WACA,WACA,GAAG,QACwD;AAC3D,QAAO,0BAA0B,MAAM;EACrC,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,eAAe,WAAW,YAAY,OAAO,gBAAgB;GAC9D;EACD,OAAO,EAAE,QAAQ,YAAY,gBAAgB;GAC3C,MAAM,QAAQ,OAAO;AACrB,OAAI,UAAU,OACZ,YAAW,qBAAqB;IAC9B,cAAc,CAAC,IAAI;IACnB,iBAAiB;IAClB,CAAC;AAGJ,4BAAyB,cAAc,QAAQ,MAAM;;EAExD,CAAC;;AAGJ,SAAS,yBACP,cACA,MACA,OACM;AACN,mBAAkB,cAAc,MAAM,KAAK,gBAAgB;AAC3D,mBAAkB,cAAc,QAAQ,KAAK,KAAK;AAElD,KAAI,OAAO,KAAK,gBAAgB,SAC9B,mBAAkB,cAAc,eAAe,KAAK,YAAY;AAGlE,KAAI,UAAU,OACZ,kBAAiB,cAAc,SAAS,eAAe,2BAA2B,MAAM,CAAC,CAAC;AAG5F,KAAI,KAAK,OACP,mBAAkB,cAAc,KAAK,OAAO;;AAIhD,SAAS,kBACP,cACA,QACM;AACN,KAAI,OAAO,UACT,kBAAiB,cAAc,UAAU;EACvC,WAAW,OAAO;EAClB,UAAU,OAAO;EAClB,CAAC;;AAIN,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;EACf,MAAM,2CAA2B,IAAI,KAKlC;AAEH,OAAK,MAAM,CAAC,iBAAiB,kBAAkB,OAAO,QACpD,QAAQ,QAAQ,kBAAkB,EAAE,CACrC,CACC,0BAAyB,IAAI,iBAAiB;GAC5C,IAAI;GACJ,UAAU,QAAQ,SAAS,sBACzB,kBACA,iBACA,KACE,QAAQ,MAAM,mBACd,uBAAuB,iBAAiB,cAAc,QAAQ,OAAU,CACzE,CACF;GACD,SAAS;IACP;IACA,GAAG;IACJ;GACF,CAAC;AAGJ,OAAK,MAAM,mBAAmB,sCAC5B,SACA,iBACD,EAAE;AACD,OAAI,yBAAyB,IAAI,gBAAgB,CAC/C;AAGF,4BAAyB,IAAI,iBAAiB;IAC5C,IAAI;IACJ,UAAU,QAAQ,SAAS,sBACzB,kBACA,iBACA,KAAK,QAAQ,MAAM,mBAAmB,GAAG,gBAAgB,KAAK,CAC/D;IACD,SAAS;KACP;KACA,MAAM;KACN,OAAO;MAAE,MAAM;MAAU,YAAY,EAAE;MAAE;KAC1C;IACF,CAAC;;AAGJ,SAAO,CAAC,GAAG,yBAAyB,QAAQ,CAAC;;CAE/C,UAAU;CACX"}
|
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { collectEnvironmentCredentialReferenceIds } from "../collector-common.js";
|
|
2
|
+
import { generateFactorySourceFile } from "../simple-factory-generator.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { join } from "node:path";
|
|
4
5
|
|
|
5
6
|
//#region src/commands/pull-v4/generators/environment-generator.ts
|
|
6
|
-
const EnvironmentCredentialSchema = FullProjectDefinitionSchema.shape.credentialReferences.unwrap().valueType.omit({
|
|
7
|
-
createdBy: true,
|
|
8
|
-
toolId: true,
|
|
9
|
-
userId: true
|
|
10
|
-
});
|
|
11
|
-
const EnvironmentSettingsSchema = z.looseObject({ credentials: z.record(z.string(), EnvironmentCredentialSchema).nullable().optional() });
|
|
12
7
|
const EnvironmentIndexSchema = z.array(z.string());
|
|
13
|
-
function generateEnvironmentSettingsDefinition(environmentName, environmentData) {
|
|
14
|
-
const environmentNameResult = z.string().nonempty().safeParse(environmentName);
|
|
15
|
-
if (!environmentNameResult.success) throw new Error(`Validation failed for environment name:\n${z.prettifyError(environmentNameResult.error)}`);
|
|
16
|
-
const result = EnvironmentSettingsSchema.safeParse(environmentData);
|
|
17
|
-
if (!result.success) throw new Error(`Validation failed for environment settings:\n${z.prettifyError(result.error)}`);
|
|
18
|
-
const parsed = result.data;
|
|
19
|
-
const { sourceFile, configObject } = createFactoryDefinition({
|
|
20
|
-
importName: "registerEnvironmentSettings",
|
|
21
|
-
variableName: environmentNameResult.data
|
|
22
|
-
});
|
|
23
|
-
addValueToObject(configObject, "credentials", parsed.credentials ?? {});
|
|
24
|
-
return sourceFile;
|
|
25
|
-
}
|
|
26
8
|
function generateEnvironmentIndexDefinition(environments) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
return generateFactorySourceFile(environments, {
|
|
10
|
+
schema: EnvironmentIndexSchema,
|
|
11
|
+
factory: {
|
|
12
|
+
importName: "createEnvironmentSettings",
|
|
13
|
+
variableName: () => "envSettings"
|
|
14
|
+
},
|
|
15
|
+
render({ parsed, sourceFile, configObject }) {
|
|
16
|
+
for (const environmentName of parsed) sourceFile.addImportDeclaration({
|
|
17
|
+
namedImports: [environmentName],
|
|
18
|
+
moduleSpecifier: `./${environmentName}.env`
|
|
19
|
+
});
|
|
20
|
+
for (const environmentName of parsed) configObject.addShorthandPropertyAssignment({ name: environmentName });
|
|
21
|
+
}
|
|
36
22
|
});
|
|
37
|
-
for (const environmentName of result.data) configObject.addShorthandPropertyAssignment({ name: environmentName });
|
|
38
|
-
return sourceFile;
|
|
39
23
|
}
|
|
24
|
+
const task = {
|
|
25
|
+
type: "environment-index",
|
|
26
|
+
collect(context) {
|
|
27
|
+
if (collectEnvironmentCredentialReferenceIds(context.project).length === 0) return [];
|
|
28
|
+
return [{
|
|
29
|
+
id: "index",
|
|
30
|
+
filePath: context.resolver.resolveOutputFilePath("environments", "index", join(context.paths.environmentsDir, "index.ts")),
|
|
31
|
+
payload: ["development"]
|
|
32
|
+
}];
|
|
33
|
+
},
|
|
34
|
+
generate: generateEnvironmentIndexDefinition
|
|
35
|
+
};
|
|
40
36
|
|
|
41
37
|
//#endregion
|
|
42
|
-
export { generateEnvironmentIndexDefinition,
|
|
38
|
+
export { generateEnvironmentIndexDefinition, task };
|
|
43
39
|
//# sourceMappingURL=environment-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/environment-generator.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"environment-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/environment-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport type { SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { collectEnvironmentCredentialReferenceIds } from '../collector-common';\nimport type { GenerationTask } from '../generation-types';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\n\nconst EnvironmentIndexSchema = z.array(z.string());\n\ntype EnvironmentIndexInput = z.input<typeof EnvironmentIndexSchema>;\n\nexport function generateEnvironmentIndexDefinition(\n environments: EnvironmentIndexInput\n): SourceFile {\n return generateFactorySourceFile(environments, {\n schema: EnvironmentIndexSchema,\n factory: {\n importName: 'createEnvironmentSettings',\n variableName: () => 'envSettings',\n },\n render({ parsed, sourceFile, configObject }) {\n for (const environmentName of parsed) {\n sourceFile.addImportDeclaration({\n namedImports: [environmentName],\n moduleSpecifier: `./${environmentName}.env`,\n });\n }\n\n for (const environmentName of parsed) {\n configObject.addShorthandPropertyAssignment({ name: environmentName });\n }\n },\n });\n}\n\nexport const task = {\n type: 'environment-index',\n collect(context) {\n const credentialReferenceIds = collectEnvironmentCredentialReferenceIds(context.project);\n if (credentialReferenceIds.length === 0) {\n return [];\n }\n\n return [\n {\n id: 'index',\n filePath: context.resolver.resolveOutputFilePath(\n 'environments',\n 'index',\n join(context.paths.environmentsDir, 'index.ts')\n ),\n payload: ['development'] as Parameters<typeof generateEnvironmentIndexDefinition>[0],\n },\n ];\n },\n generate: generateEnvironmentIndexDefinition,\n} satisfies GenerationTask<Parameters<typeof generateEnvironmentIndexDefinition>[0]>;\n"],"mappings":";;;;;;AAOA,MAAM,yBAAyB,EAAE,MAAM,EAAE,QAAQ,CAAC;AAIlD,SAAgB,mCACd,cACY;AACZ,QAAO,0BAA0B,cAAc;EAC7C,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,oBAAoB;GACrB;EACD,OAAO,EAAE,QAAQ,YAAY,gBAAgB;AAC3C,QAAK,MAAM,mBAAmB,OAC5B,YAAW,qBAAqB;IAC9B,cAAc,CAAC,gBAAgB;IAC/B,iBAAiB,KAAK,gBAAgB;IACvC,CAAC;AAGJ,QAAK,MAAM,mBAAmB,OAC5B,cAAa,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;;EAG3E,CAAC;;AAGJ,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;AAEf,MAD+B,yCAAyC,QAAQ,QAAQ,CAC7D,WAAW,EACpC,QAAO,EAAE;AAGX,SAAO,CACL;GACE,IAAI;GACJ,UAAU,QAAQ,SAAS,sBACzB,gBACA,SACA,KAAK,QAAQ,MAAM,iBAAiB,WAAW,CAChD;GACD,SAAS,CAAC,cAAc;GACzB,CACF;;CAEH,UAAU;CACX"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { asRecord, collectEnvironmentCredentialReferenceIds } from "../collector-common.js";
|
|
2
|
+
import { generateSimpleFactoryDefinition, validateGeneratorInput } from "../simple-factory-generator.js";
|
|
3
|
+
import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/pull-v4/generators/environment-settings-generator.ts
|
|
8
|
+
const EnvironmentCredentialSchema = FullProjectDefinitionSchema.shape.credentialReferences.unwrap().valueType.omit({
|
|
9
|
+
createdBy: true,
|
|
10
|
+
toolId: true,
|
|
11
|
+
userId: true
|
|
12
|
+
});
|
|
13
|
+
const EnvironmentSettingsSchema = z.looseObject({ credentials: z.record(z.string(), EnvironmentCredentialSchema).nullable().optional() });
|
|
14
|
+
function generateEnvironmentSettingsDefinition(environmentName, environmentData) {
|
|
15
|
+
const validatedEnvironmentName = validateGeneratorInput(environmentName, {
|
|
16
|
+
schema: z.string().nonempty(),
|
|
17
|
+
errorLabel: "environment name"
|
|
18
|
+
});
|
|
19
|
+
return generateSimpleFactoryDefinition(environmentData, {
|
|
20
|
+
schema: EnvironmentSettingsSchema,
|
|
21
|
+
factory: {
|
|
22
|
+
importName: "registerEnvironmentSettings",
|
|
23
|
+
variableName: () => validatedEnvironmentName
|
|
24
|
+
},
|
|
25
|
+
buildConfig(parsed) {
|
|
26
|
+
return { credentials: parsed.credentials ?? {} };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const task = {
|
|
31
|
+
type: "environment-settings",
|
|
32
|
+
collect(context) {
|
|
33
|
+
const credentialReferenceIds = collectEnvironmentCredentialReferenceIds(context.project);
|
|
34
|
+
if (credentialReferenceIds.length === 0) return [];
|
|
35
|
+
const credentials = {};
|
|
36
|
+
for (const credentialReferenceId of credentialReferenceIds) {
|
|
37
|
+
const credentialData = context.project.credentialReferences?.[credentialReferenceId];
|
|
38
|
+
const credentialRecord = asRecord(credentialData);
|
|
39
|
+
credentials[credentialReferenceId] = credentialRecord ? {
|
|
40
|
+
...credentialRecord,
|
|
41
|
+
id: credentialReferenceId
|
|
42
|
+
} : { id: credentialReferenceId };
|
|
43
|
+
}
|
|
44
|
+
return [{
|
|
45
|
+
id: "development",
|
|
46
|
+
filePath: context.resolver.resolveOutputFilePath("environments", "development", join(context.paths.environmentsDir, "development.env.ts")),
|
|
47
|
+
payload: { credentials }
|
|
48
|
+
}];
|
|
49
|
+
},
|
|
50
|
+
generate(payload) {
|
|
51
|
+
return generateEnvironmentSettingsDefinition("development", payload);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { generateEnvironmentSettingsDefinition, task };
|
|
57
|
+
//# sourceMappingURL=environment-settings-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-settings-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/environment-settings-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 { asRecord, collectEnvironmentCredentialReferenceIds } from '../collector-common';\nimport type { GenerationTask } from '../generation-types';\nimport {\n generateSimpleFactoryDefinition,\n validateGeneratorInput,\n} from '../simple-factory-generator';\n\nconst EnvironmentCredentialSchema = FullProjectDefinitionSchema.shape.credentialReferences\n .unwrap()\n .valueType.omit({\n createdBy: true,\n toolId: true,\n userId: true,\n });\nconst EnvironmentSettingsSchema = z.looseObject({\n credentials: z.record(z.string(), EnvironmentCredentialSchema).nullable().optional(),\n});\ntype EnvironmentSettingsInput = z.input<typeof EnvironmentSettingsSchema>;\n\nexport function generateEnvironmentSettingsDefinition(\n environmentName: string,\n environmentData: EnvironmentSettingsInput\n): SourceFile {\n const validatedEnvironmentName = validateGeneratorInput(environmentName, {\n schema: z.string().nonempty(),\n errorLabel: 'environment name',\n });\n\n return generateSimpleFactoryDefinition(environmentData, {\n schema: EnvironmentSettingsSchema,\n factory: {\n importName: 'registerEnvironmentSettings',\n variableName: () => validatedEnvironmentName,\n },\n buildConfig(parsed) {\n return {\n credentials: parsed.credentials ?? {},\n };\n },\n });\n}\n\nexport const task = {\n type: 'environment-settings',\n collect(context) {\n const credentialReferenceIds = collectEnvironmentCredentialReferenceIds(context.project);\n if (credentialReferenceIds.length === 0) {\n return [];\n }\n\n const credentials: Record<string, unknown> = {};\n for (const credentialReferenceId of credentialReferenceIds) {\n const credentialData = context.project.credentialReferences?.[credentialReferenceId];\n const credentialRecord = asRecord(credentialData);\n credentials[credentialReferenceId] = credentialRecord\n ? { ...credentialRecord, id: credentialReferenceId }\n : { id: credentialReferenceId };\n }\n\n return [\n {\n id: 'development',\n filePath: context.resolver.resolveOutputFilePath(\n 'environments',\n 'development',\n join(context.paths.environmentsDir, 'development.env.ts')\n ),\n payload: {\n credentials,\n } as Parameters<typeof generateEnvironmentSettingsDefinition>[1],\n },\n ];\n },\n generate(payload) {\n return generateEnvironmentSettingsDefinition('development', payload);\n },\n} satisfies GenerationTask<Parameters<typeof generateEnvironmentSettingsDefinition>[1]>;\n"],"mappings":";;;;;;;AAWA,MAAM,8BAA8B,4BAA4B,MAAM,qBACnE,QAAQ,CACR,UAAU,KAAK;CACd,WAAW;CACX,QAAQ;CACR,QAAQ;CACT,CAAC;AACJ,MAAM,4BAA4B,EAAE,YAAY,EAC9C,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,4BAA4B,CAAC,UAAU,CAAC,UAAU,EACrF,CAAC;AAGF,SAAgB,sCACd,iBACA,iBACY;CACZ,MAAM,2BAA2B,uBAAuB,iBAAiB;EACvE,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC7B,YAAY;EACb,CAAC;AAEF,QAAO,gCAAgC,iBAAiB;EACtD,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,oBAAoB;GACrB;EACD,YAAY,QAAQ;AAClB,UAAO,EACL,aAAa,OAAO,eAAe,EAAE,EACtC;;EAEJ,CAAC;;AAGJ,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;EACf,MAAM,yBAAyB,yCAAyC,QAAQ,QAAQ;AACxF,MAAI,uBAAuB,WAAW,EACpC,QAAO,EAAE;EAGX,MAAM,cAAuC,EAAE;AAC/C,OAAK,MAAM,yBAAyB,wBAAwB;GAC1D,MAAM,iBAAiB,QAAQ,QAAQ,uBAAuB;GAC9D,MAAM,mBAAmB,SAAS,eAAe;AACjD,eAAY,yBAAyB,mBACjC;IAAE,GAAG;IAAkB,IAAI;IAAuB,GAClD,EAAE,IAAI,uBAAuB;;AAGnC,SAAO,CACL;GACE,IAAI;GACJ,UAAU,QAAQ,SAAS,sBACzB,gBACA,eACA,KAAK,QAAQ,MAAM,iBAAiB,qBAAqB,CAC1D;GACD,SAAS,EACP,aACD;GACF,CACF;;CAEH,SAAS,SAAS;AAChB,SAAO,sCAAsC,eAAe,QAAQ;;CAEvE"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { codeReference } from "../utils/code-values.js";
|
|
2
|
+
import { toCamelCase } from "../utils/naming.js";
|
|
3
|
+
import { addValueToObject } from "../utils/factory-writer.js";
|
|
4
|
+
import "../utils/index.js";
|
|
5
|
+
import { asRecord } from "../collector-common.js";
|
|
6
|
+
import { buildSequentialNameFileNames, resolveExternalAgentNamingSeed } from "../generation-resolver.js";
|
|
7
|
+
import { generateSimpleFactoryDefinition } from "../simple-factory-generator.js";
|
|
8
|
+
import { addNamedImports, applyImportPlan, createImportPlan } from "../import-plan.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/external-agent-generator.ts
|
|
6
14
|
const MySchema = FullProjectDefinitionSchema.shape.externalAgents.unwrap().valueType.omit({ id: true });
|
|
@@ -10,30 +18,50 @@ const ExternalAgentSchema = z.strictObject({
|
|
|
10
18
|
...MySchema.shape
|
|
11
19
|
});
|
|
12
20
|
function generateExternalAgentDefinition({ id, tenantId, projectId, createdAt, updatedAt, ...data }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
return generateSimpleFactoryDefinition(data, {
|
|
22
|
+
schema: ExternalAgentSchema,
|
|
23
|
+
factory: {
|
|
24
|
+
importName: "externalAgent",
|
|
25
|
+
variableName: (parsed) => parsed.externalAgentReferenceName ?? toCamelCase(parsed.externalAgentId)
|
|
26
|
+
},
|
|
27
|
+
buildConfig(parsed) {
|
|
28
|
+
const { externalAgentReferenceName: _externalAgentReferenceName, externalAgentId, credentialReferenceId: _credentialReferenceId, ...rest } = parsed;
|
|
29
|
+
return {
|
|
30
|
+
id: externalAgentId,
|
|
31
|
+
...rest
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
finalize({ parsed, sourceFile, configObject }) {
|
|
35
|
+
if (!parsed.credentialReferenceId) return;
|
|
36
|
+
const credentialReferenceName = toCamelCase(parsed.credentialReferenceId);
|
|
37
|
+
const importPlan = createImportPlan();
|
|
38
|
+
addNamedImports(importPlan, `../credentials/${parsed.credentialReferenceId}`, credentialReferenceName);
|
|
39
|
+
applyImportPlan(sourceFile, importPlan);
|
|
40
|
+
addValueToObject(configObject, "credentialReference", codeReference(credentialReferenceName));
|
|
41
|
+
}
|
|
19
42
|
});
|
|
20
|
-
for (const [key, value] of Object.entries({
|
|
21
|
-
id: externalAgentId,
|
|
22
|
-
...parsed
|
|
23
|
-
})) addValueToObject(configObject, key, value);
|
|
24
|
-
if (credentialReferenceId) {
|
|
25
|
-
sourceFile.addImportDeclaration({
|
|
26
|
-
namedImports: [toCamelCase(credentialReferenceId)],
|
|
27
|
-
moduleSpecifier: `../credentials/${credentialReferenceId}`
|
|
28
|
-
});
|
|
29
|
-
configObject.addPropertyAssignment({
|
|
30
|
-
name: "credentialReference",
|
|
31
|
-
initializer: toCamelCase(credentialReferenceId)
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return sourceFile;
|
|
35
43
|
}
|
|
44
|
+
const task = {
|
|
45
|
+
type: "external-agent",
|
|
46
|
+
collect(context) {
|
|
47
|
+
const externalAgentEntries = Object.entries(context.project.externalAgents ?? {});
|
|
48
|
+
const fileNamesByExternalAgentId = buildSequentialNameFileNames(externalAgentEntries.map(([externalAgentId, externalAgentData]) => [externalAgentId, { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) }]));
|
|
49
|
+
return externalAgentEntries.map(([externalAgentId, externalAgentData]) => {
|
|
50
|
+
const externalAgentRecord = asRecord(externalAgentData) ?? {};
|
|
51
|
+
return {
|
|
52
|
+
id: externalAgentId,
|
|
53
|
+
filePath: context.resolver.resolveOutputFilePath("externalAgents", externalAgentId, join(context.paths.externalAgentsDir, fileNamesByExternalAgentId[externalAgentId])),
|
|
54
|
+
payload: {
|
|
55
|
+
externalAgentId,
|
|
56
|
+
externalAgentReferenceName: context.resolver.getExternalAgentReferenceName(externalAgentId),
|
|
57
|
+
...externalAgentRecord
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
generate: generateExternalAgentDefinition
|
|
63
|
+
};
|
|
36
64
|
|
|
37
65
|
//#endregion
|
|
38
|
-
export { generateExternalAgentDefinition };
|
|
66
|
+
export { generateExternalAgentDefinition, task };
|
|
39
67
|
//# sourceMappingURL=external-agent-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-agent-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/external-agent-generator.ts"],"sourcesContent":["import { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { addValueToObject,
|
|
1
|
+
{"version":3,"file":"external-agent-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/external-agent-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 { asRecord } from '../collector-common';\nimport {\n buildSequentialNameFileNames,\n resolveExternalAgentNamingSeed,\n} from '../generation-resolver';\nimport type { GenerationTask } from '../generation-types';\nimport { addNamedImports, applyImportPlan, createImportPlan } from '../import-plan';\nimport { generateSimpleFactoryDefinition } from '../simple-factory-generator';\nimport { addValueToObject, codeReference, toCamelCase } from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.externalAgents.unwrap().valueType.omit({\n id: true,\n});\n\nconst ExternalAgentSchema = z.strictObject({\n externalAgentId: z.string().nonempty(),\n externalAgentReferenceName: z.string().optional(),\n ...MySchema.shape,\n});\n\ntype ExternalAgentInput = z.input<typeof ExternalAgentSchema>;\n\nexport function generateExternalAgentDefinition({\n id,\n tenantId,\n projectId,\n createdAt,\n updatedAt,\n ...data\n}: ExternalAgentInput & Record<string, unknown>): SourceFile {\n return generateSimpleFactoryDefinition(data, {\n schema: ExternalAgentSchema,\n factory: {\n importName: 'externalAgent',\n variableName: (parsed) =>\n parsed.externalAgentReferenceName ?? toCamelCase(parsed.externalAgentId),\n },\n buildConfig(parsed) {\n const {\n externalAgentReferenceName: _externalAgentReferenceName,\n externalAgentId,\n credentialReferenceId: _credentialReferenceId,\n ...rest\n } = parsed;\n return {\n id: externalAgentId,\n ...rest,\n };\n },\n finalize({ parsed, sourceFile, configObject }) {\n if (!parsed.credentialReferenceId) {\n return;\n }\n\n const credentialReferenceName = toCamelCase(parsed.credentialReferenceId);\n const importPlan = createImportPlan();\n addNamedImports(\n importPlan,\n `../credentials/${parsed.credentialReferenceId}`,\n credentialReferenceName\n );\n applyImportPlan(sourceFile, importPlan);\n addValueToObject(configObject, 'credentialReference', codeReference(credentialReferenceName));\n },\n });\n}\n\nexport const task = {\n type: 'external-agent',\n collect(context) {\n const externalAgentEntries = Object.entries(context.project.externalAgents ?? {});\n const fileNamesByExternalAgentId = buildSequentialNameFileNames(\n externalAgentEntries.map(([externalAgentId, externalAgentData]) => [\n externalAgentId,\n { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) },\n ])\n );\n\n return externalAgentEntries.map(([externalAgentId, externalAgentData]) => {\n const externalAgentRecord = asRecord(externalAgentData) ?? {};\n return {\n id: externalAgentId,\n filePath: context.resolver.resolveOutputFilePath(\n 'externalAgents',\n externalAgentId,\n join(context.paths.externalAgentsDir, fileNamesByExternalAgentId[externalAgentId])\n ),\n payload: {\n externalAgentId,\n externalAgentReferenceName:\n context.resolver.getExternalAgentReferenceName(externalAgentId),\n ...externalAgentRecord,\n } as Parameters<typeof generateExternalAgentDefinition>[0],\n };\n });\n },\n generate: generateExternalAgentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateExternalAgentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,WAAW,4BAA4B,MAAM,eAAe,QAAQ,CAAC,UAAU,KAAK,EACxF,IAAI,MACL,CAAC;AAEF,MAAM,sBAAsB,EAAE,aAAa;CACzC,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,4BAA4B,EAAE,QAAQ,CAAC,UAAU;CACjD,GAAG,SAAS;CACb,CAAC;AAIF,SAAgB,gCAAgC,EAC9C,IACA,UACA,WACA,WACA,WACA,GAAG,QACwD;AAC3D,QAAO,gCAAgC,MAAM;EAC3C,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,eAAe,WACb,OAAO,8BAA8B,YAAY,OAAO,gBAAgB;GAC3E;EACD,YAAY,QAAQ;GAClB,MAAM,EACJ,4BAA4B,6BAC5B,iBACA,uBAAuB,wBACvB,GAAG,SACD;AACJ,UAAO;IACL,IAAI;IACJ,GAAG;IACJ;;EAEH,SAAS,EAAE,QAAQ,YAAY,gBAAgB;AAC7C,OAAI,CAAC,OAAO,sBACV;GAGF,MAAM,0BAA0B,YAAY,OAAO,sBAAsB;GACzE,MAAM,aAAa,kBAAkB;AACrC,mBACE,YACA,kBAAkB,OAAO,yBACzB,wBACD;AACD,mBAAgB,YAAY,WAAW;AACvC,oBAAiB,cAAc,uBAAuB,cAAc,wBAAwB,CAAC;;EAEhG,CAAC;;AAGJ,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;EACf,MAAM,uBAAuB,OAAO,QAAQ,QAAQ,QAAQ,kBAAkB,EAAE,CAAC;EACjF,MAAM,6BAA6B,6BACjC,qBAAqB,KAAK,CAAC,iBAAiB,uBAAuB,CACjE,iBACA,EAAE,MAAM,+BAA+B,iBAAiB,kBAAkB,EAAE,CAC7E,CAAC,CACH;AAED,SAAO,qBAAqB,KAAK,CAAC,iBAAiB,uBAAuB;GACxE,MAAM,sBAAsB,SAAS,kBAAkB,IAAI,EAAE;AAC7D,UAAO;IACL,IAAI;IACJ,UAAU,QAAQ,SAAS,sBACzB,kBACA,iBACA,KAAK,QAAQ,MAAM,mBAAmB,2BAA2B,iBAAiB,CACnF;IACD,SAAS;KACP;KACA,4BACE,QAAQ,SAAS,8BAA8B,gBAAgB;KACjE,GAAG;KACJ;IACF;IACD;;CAEJ,UAAU;CACX"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { codeExpression } from "../utils/code-values.js";
|
|
2
|
+
import { toToolReferenceName } from "../utils/naming.js";
|
|
3
|
+
import { addValueToObject } from "../utils/factory-writer.js";
|
|
4
|
+
import "../utils/index.js";
|
|
5
|
+
import { stripExtension } from "../collector-common.js";
|
|
6
|
+
import { buildSequentialNameFileNames, collectFunctionToolEntries } from "../generation-resolver.js";
|
|
7
|
+
import { generateSimpleFactoryDefinition } from "../simple-factory-generator.js";
|
|
2
8
|
import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
|
|
3
9
|
import { z } from "zod";
|
|
10
|
+
import { join } from "node:path";
|
|
4
11
|
|
|
5
12
|
//#region src/commands/pull-v4/generators/function-tool-generator.ts
|
|
6
13
|
const MySchema = FullProjectDefinitionSchema.shape.functions.unwrap().valueType.omit({ id: true });
|
|
@@ -16,21 +23,50 @@ const FunctionToolSchema = z.strictObject({
|
|
|
16
23
|
functionToolId: z.string().nonempty()
|
|
17
24
|
});
|
|
18
25
|
function generateFunctionToolDefinition(data) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
return generateSimpleFactoryDefinition(data, {
|
|
27
|
+
schema: FunctionToolSchema,
|
|
28
|
+
factory: {
|
|
29
|
+
importName: "functionTool",
|
|
30
|
+
variableName: (parsed) => toToolReferenceName(parsed.name || parsed.functionToolId)
|
|
31
|
+
},
|
|
32
|
+
buildConfig(parsed) {
|
|
33
|
+
const { functionToolId: _functionToolId, executeCode: _executeCode, ...rest } = parsed;
|
|
34
|
+
return rest;
|
|
35
|
+
},
|
|
36
|
+
finalize({ parsed, configObject }) {
|
|
37
|
+
if (!parsed.executeCode) return;
|
|
38
|
+
addValueToObject(configObject, "execute", codeExpression(parsed.executeCode));
|
|
39
|
+
}
|
|
25
40
|
});
|
|
26
|
-
for (const [k, v] of Object.entries(parsed)) addValueToObject(configObject, k, v);
|
|
27
|
-
if (executeCode) configObject.addPropertyAssignment({
|
|
28
|
-
name: "execute",
|
|
29
|
-
initializer: executeCode
|
|
30
|
-
});
|
|
31
|
-
return sourceFile;
|
|
32
41
|
}
|
|
42
|
+
const task = {
|
|
43
|
+
type: "function-tool",
|
|
44
|
+
collect(context) {
|
|
45
|
+
const functionToolEntries = collectFunctionToolEntries(context.project);
|
|
46
|
+
if (!functionToolEntries.length) return [];
|
|
47
|
+
const fileNamesByFunctionToolId = buildSequentialNameFileNames(functionToolEntries.map(({ functionToolId, fileName }) => [functionToolId, { name: fileName }]));
|
|
48
|
+
return functionToolEntries.map(({ functionToolId, functionToolData, functionData }) => {
|
|
49
|
+
const modulePath = stripExtension(fileNamesByFunctionToolId[functionToolId]);
|
|
50
|
+
const functionToolName = typeof functionToolData.name === "string" && functionToolData.name.length > 0 ? functionToolData.name : typeof functionData.name === "string" && functionData.name.length > 0 ? functionData.name : void 0;
|
|
51
|
+
const functionToolDescription = typeof functionToolData.description === "string" ? functionToolData.description : typeof functionData.description === "string" ? functionData.description : void 0;
|
|
52
|
+
return {
|
|
53
|
+
id: functionToolId,
|
|
54
|
+
filePath: context.resolver.resolveOutputFilePath("functionTools", functionToolId, join(context.paths.toolsDir, `${modulePath}.ts`)),
|
|
55
|
+
payload: {
|
|
56
|
+
functionToolId,
|
|
57
|
+
...functionToolName && { name: functionToolName },
|
|
58
|
+
...functionToolDescription !== void 0 && { description: functionToolDescription },
|
|
59
|
+
...functionData.inputSchema !== void 0 && { inputSchema: functionData.inputSchema },
|
|
60
|
+
...functionData.schema !== void 0 && { schema: functionData.schema },
|
|
61
|
+
...functionData.executeCode !== void 0 && { executeCode: functionData.executeCode },
|
|
62
|
+
...functionData.dependencies !== void 0 && { dependencies: functionData.dependencies }
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
generate: generateFunctionToolDefinition
|
|
68
|
+
};
|
|
33
69
|
|
|
34
70
|
//#endregion
|
|
35
|
-
export { generateFunctionToolDefinition };
|
|
71
|
+
export { generateFunctionToolDefinition, task };
|
|
36
72
|
//# sourceMappingURL=function-tool-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-tool-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/function-tool-generator.ts"],"sourcesContent":["import { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport type { SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { addValueToObject,
|
|
1
|
+
{"version":3,"file":"function-tool-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/function-tool-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 { stripExtension } from '../collector-common';\nimport { buildSequentialNameFileNames, collectFunctionToolEntries } from '../generation-resolver';\nimport type { GenerationTask } from '../generation-types';\nimport { generateSimpleFactoryDefinition } from '../simple-factory-generator';\nimport { addValueToObject, codeExpression, toToolReferenceName } from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.functions.unwrap().valueType.omit({\n id: true,\n});\nconst MySchema2 = FullProjectDefinitionSchema.shape.functionTools.unwrap().valueType.omit({\n id: true,\n functionId: true,\n});\n\nconst FunctionToolSchema = z.strictObject({\n ...MySchema.shape,\n ...MySchema2.shape,\n name: z.preprocess((v) => v ?? '', MySchema2.shape.name),\n // Even empty description should exist, otherwise agent-sdk show type error\n // dependencies: z.preprocess(\n // (v) => (v && Object.keys(v).length && v) || undefined,\n // MySchema.shape.dependencies\n // ),\n description: z.preprocess((v) => v || undefined, MySchema2.shape.description),\n functionToolId: z.string().nonempty(),\n});\n\ntype FunctionToolInput = z.input<typeof FunctionToolSchema>;\n\nexport function generateFunctionToolDefinition(data: FunctionToolInput): SourceFile {\n return generateSimpleFactoryDefinition(data, {\n schema: FunctionToolSchema,\n factory: {\n importName: 'functionTool',\n variableName: (parsed) => toToolReferenceName(parsed.name || parsed.functionToolId),\n },\n buildConfig(parsed) {\n const { functionToolId: _functionToolId, executeCode: _executeCode, ...rest } = parsed;\n return rest;\n },\n finalize({ parsed, configObject }) {\n if (!parsed.executeCode) {\n return;\n }\n\n addValueToObject(configObject, 'execute', codeExpression(parsed.executeCode));\n },\n });\n}\n\nexport const task = {\n type: 'function-tool',\n collect(context) {\n const functionToolEntries = collectFunctionToolEntries(context.project);\n if (!functionToolEntries.length) {\n return [];\n }\n\n const fileNamesByFunctionToolId = buildSequentialNameFileNames(\n functionToolEntries.map(({ functionToolId, fileName }) => [\n functionToolId,\n { name: fileName },\n ])\n );\n\n return functionToolEntries.map(({ functionToolId, functionToolData, functionData }) => {\n const modulePath = stripExtension(fileNamesByFunctionToolId[functionToolId]);\n const functionToolName =\n typeof functionToolData.name === 'string' && functionToolData.name.length > 0\n ? functionToolData.name\n : typeof functionData.name === 'string' && functionData.name.length > 0\n ? functionData.name\n : undefined;\n const functionToolDescription =\n typeof functionToolData.description === 'string'\n ? functionToolData.description\n : typeof functionData.description === 'string'\n ? functionData.description\n : undefined;\n\n return {\n id: functionToolId,\n filePath: context.resolver.resolveOutputFilePath(\n 'functionTools',\n functionToolId,\n join(context.paths.toolsDir, `${modulePath}.ts`)\n ),\n payload: {\n functionToolId,\n ...(functionToolName && { name: functionToolName }),\n ...(functionToolDescription !== undefined && { description: functionToolDescription }),\n ...(functionData.inputSchema !== undefined && { inputSchema: functionData.inputSchema }),\n ...(functionData.schema !== undefined && { schema: functionData.schema }),\n ...(functionData.executeCode !== undefined && { executeCode: functionData.executeCode }),\n ...(functionData.dependencies !== undefined && {\n dependencies: functionData.dependencies,\n }),\n } as Parameters<typeof generateFunctionToolDefinition>[0],\n };\n });\n },\n generate: generateFunctionToolDefinition,\n} satisfies GenerationTask<Parameters<typeof generateFunctionToolDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,WAAW,4BAA4B,MAAM,UAAU,QAAQ,CAAC,UAAU,KAAK,EACnF,IAAI,MACL,CAAC;AACF,MAAM,YAAY,4BAA4B,MAAM,cAAc,QAAQ,CAAC,UAAU,KAAK;CACxF,IAAI;CACJ,YAAY;CACb,CAAC;AAEF,MAAM,qBAAqB,EAAE,aAAa;CACxC,GAAG,SAAS;CACZ,GAAG,UAAU;CACb,MAAM,EAAE,YAAY,MAAM,KAAK,IAAI,UAAU,MAAM,KAAK;CAMxD,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,UAAU,MAAM,YAAY;CAC7E,gBAAgB,EAAE,QAAQ,CAAC,UAAU;CACtC,CAAC;AAIF,SAAgB,+BAA+B,MAAqC;AAClF,QAAO,gCAAgC,MAAM;EAC3C,QAAQ;EACR,SAAS;GACP,YAAY;GACZ,eAAe,WAAW,oBAAoB,OAAO,QAAQ,OAAO,eAAe;GACpF;EACD,YAAY,QAAQ;GAClB,MAAM,EAAE,gBAAgB,iBAAiB,aAAa,cAAc,GAAG,SAAS;AAChF,UAAO;;EAET,SAAS,EAAE,QAAQ,gBAAgB;AACjC,OAAI,CAAC,OAAO,YACV;AAGF,oBAAiB,cAAc,WAAW,eAAe,OAAO,YAAY,CAAC;;EAEhF,CAAC;;AAGJ,MAAa,OAAO;CAClB,MAAM;CACN,QAAQ,SAAS;EACf,MAAM,sBAAsB,2BAA2B,QAAQ,QAAQ;AACvE,MAAI,CAAC,oBAAoB,OACvB,QAAO,EAAE;EAGX,MAAM,4BAA4B,6BAChC,oBAAoB,KAAK,EAAE,gBAAgB,eAAe,CACxD,gBACA,EAAE,MAAM,UAAU,CACnB,CAAC,CACH;AAED,SAAO,oBAAoB,KAAK,EAAE,gBAAgB,kBAAkB,mBAAmB;GACrF,MAAM,aAAa,eAAe,0BAA0B,gBAAgB;GAC5E,MAAM,mBACJ,OAAO,iBAAiB,SAAS,YAAY,iBAAiB,KAAK,SAAS,IACxE,iBAAiB,OACjB,OAAO,aAAa,SAAS,YAAY,aAAa,KAAK,SAAS,IAClE,aAAa,OACb;GACR,MAAM,0BACJ,OAAO,iBAAiB,gBAAgB,WACpC,iBAAiB,cACjB,OAAO,aAAa,gBAAgB,WAClC,aAAa,cACb;AAER,UAAO;IACL,IAAI;IACJ,UAAU,QAAQ,SAAS,sBACzB,iBACA,gBACA,KAAK,QAAQ,MAAM,UAAU,GAAG,WAAW,KAAK,CACjD;IACD,SAAS;KACP;KACA,GAAI,oBAAoB,EAAE,MAAM,kBAAkB;KAClD,GAAI,4BAA4B,UAAa,EAAE,aAAa,yBAAyB;KACrF,GAAI,aAAa,gBAAgB,UAAa,EAAE,aAAa,aAAa,aAAa;KACvF,GAAI,aAAa,WAAW,UAAa,EAAE,QAAQ,aAAa,QAAQ;KACxE,GAAI,aAAa,gBAAgB,UAAa,EAAE,aAAa,aAAa,aAAa;KACvF,GAAI,aAAa,iBAAiB,UAAa,EAC7C,cAAc,aAAa,cAC5B;KACF;IACF;IACD;;CAEJ,UAAU;CACX"}
|