@aigne/core 0.4.201-3 → 0.4.201-4

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.
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaToDataType = SchemaToDataType;
4
+ const nanoid_1 = require("nanoid");
5
+ const utils_1 = require("./utils");
6
+ function SchemaToDataType(dataType) {
7
+ return utils_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
8
+ switch (schema.type) {
9
+ case 'string':
10
+ return {
11
+ id: (0, nanoid_1.nanoid)(),
12
+ name,
13
+ type: 'string',
14
+ required: schema.required,
15
+ };
16
+ case 'number':
17
+ return {
18
+ id: (0, nanoid_1.nanoid)(),
19
+ name,
20
+ type: 'number',
21
+ required: schema.required,
22
+ };
23
+ case 'boolean':
24
+ return {
25
+ id: (0, nanoid_1.nanoid)(),
26
+ name,
27
+ type: 'boolean',
28
+ required: schema.required,
29
+ };
30
+ case 'object':
31
+ return {
32
+ id: (0, nanoid_1.nanoid)(),
33
+ name,
34
+ type: 'object',
35
+ required: schema.required,
36
+ properties: SchemaToDataType(schema.properties),
37
+ };
38
+ case 'array':
39
+ return {
40
+ id: (0, nanoid_1.nanoid)(),
41
+ name,
42
+ type: 'array',
43
+ required: schema.required,
44
+ items: SchemaToDataType({ items: schema.items })['items'],
45
+ };
46
+ default: {
47
+ throw new Error(`Unknown data type: ${schema.type}`);
48
+ }
49
+ }
50
+ }));
51
+ }
@@ -18,6 +18,7 @@ exports.createFunctionAgentDefinition = createFunctionAgentDefinition;
18
18
  const nanoid_1 = require("nanoid");
19
19
  const tsyringe_1 = require("tsyringe");
20
20
  const constants_1 = require("./constants");
21
+ const data_type_schema_1 = require("./data-type-schema");
21
22
  const function_runner_1 = require("./function-runner");
22
23
  const runnable_1 = require("./runnable");
23
24
  const utils_1 = require("./utils");
@@ -61,16 +62,8 @@ function createFunctionAgentDefinition(options) {
61
62
  id: options.id || options.name || (0, nanoid_1.nanoid)(),
62
63
  name: options.name,
63
64
  type: 'function_agent',
64
- inputs: utils_1.OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
65
- ...dataType,
66
- id: (0, nanoid_1.nanoid)(),
67
- name,
68
- }))),
69
- outputs: utils_1.OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { ...dataType }]) => ({
70
- ...dataType,
71
- id: (0, nanoid_1.nanoid)(),
72
- name,
73
- }))),
65
+ inputs: (0, data_type_schema_1.SchemaToDataType)(options.inputs),
66
+ outputs: (0, data_type_schema_1.SchemaToDataType)(options.outputs),
74
67
  language: options.language,
75
68
  code: options.code,
76
69
  };
package/lib/cjs/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./utils"), exports);
18
18
  __exportStar(require("./constants"), exports);
19
19
  __exportStar(require("./data-type"), exports);
20
+ __exportStar(require("./data-type-schema"), exports);
20
21
  __exportStar(require("./context"), exports);
21
22
  __exportStar(require("./runnable"), exports);
22
23
  __exportStar(require("./pipeline-agent"), exports);
@@ -19,6 +19,7 @@ const lodash_1 = require("lodash");
19
19
  const nanoid_1 = require("nanoid");
20
20
  const tsyringe_1 = require("tsyringe");
21
21
  const constants_1 = require("./constants");
22
+ const data_type_schema_1 = require("./data-type-schema");
22
23
  const llm_model_1 = require("./llm-model");
23
24
  const runnable_1 = require("./runnable");
24
25
  const utils_1 = require("./utils");
@@ -116,16 +117,8 @@ function createLLMAgentDefinition(options) {
116
117
  id: options.id || options.name || (0, nanoid_1.nanoid)(),
117
118
  name: options.name,
118
119
  type: 'llm_agent',
119
- inputs: ordered_map_1.OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
120
- ...dataType,
121
- id: (0, nanoid_1.nanoid)(),
122
- name,
123
- }))),
124
- outputs: ordered_map_1.OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { ...dataType }]) => ({
125
- ...dataType,
126
- id: (0, nanoid_1.nanoid)(),
127
- name,
128
- }))),
120
+ inputs: (0, data_type_schema_1.SchemaToDataType)(options.inputs),
121
+ outputs: (0, data_type_schema_1.SchemaToDataType)(options.outputs),
129
122
  modelOptions: options.modelOptions,
130
123
  messages: ordered_map_1.OrderedRecord.fromArray(options.messages?.map((i) => ({
131
124
  id: (0, nanoid_1.nanoid)(),
@@ -19,6 +19,7 @@ const lodash_1 = require("lodash");
19
19
  const nanoid_1 = require("nanoid");
20
20
  const tsyringe_1 = require("tsyringe");
21
21
  const constants_1 = require("./constants");
22
+ const data_type_schema_1 = require("./data-type-schema");
22
23
  const llm_model_1 = require("./llm-model");
23
24
  const runnable_1 = require("./runnable");
24
25
  const utils_1 = require("./utils");
@@ -114,11 +115,7 @@ exports.LLMDecisionAgent = LLMDecisionAgent = LLMDecisionAgent_1 = __decorate([
114
115
  __metadata("design:paramtypes", [Object, llm_model_1.LLMModel, Object])
115
116
  ], LLMDecisionAgent);
116
117
  function createLLMDecisionAgentDefinition(options) {
117
- const inputs = utils_1.OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
118
- ...dataType,
119
- id: (0, nanoid_1.nanoid)(),
120
- name: name,
121
- })));
118
+ const inputs = (0, data_type_schema_1.SchemaToDataType)(options.inputs);
122
119
  const messages = utils_1.OrderedRecord.fromArray([
123
120
  {
124
121
  id: (0, nanoid_1.nanoid)(),
@@ -18,6 +18,7 @@ exports.createLocalFunctionAgentDefinition = createLocalFunctionAgentDefinition;
18
18
  const nanoid_1 = require("nanoid");
19
19
  const tsyringe_1 = require("tsyringe");
20
20
  const constants_1 = require("./constants");
21
+ const data_type_schema_1 = require("./data-type-schema");
21
22
  const runnable_1 = require("./runnable");
22
23
  const utils_1 = require("./utils");
23
24
  let LocalFunctionAgent = LocalFunctionAgent_1 = class LocalFunctionAgent extends runnable_1.Runnable {
@@ -57,16 +58,8 @@ exports.LocalFunctionAgent = LocalFunctionAgent = LocalFunctionAgent_1 = __decor
57
58
  __metadata("design:paramtypes", [Object, Object])
58
59
  ], LocalFunctionAgent);
59
60
  function createLocalFunctionAgentDefinition(options) {
60
- const inputs = utils_1.OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, i]) => ({
61
- ...i,
62
- id: (0, nanoid_1.nanoid)(),
63
- name,
64
- })));
65
- const outputs = utils_1.OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, o]) => ({
66
- ...o,
67
- id: (0, nanoid_1.nanoid)(),
68
- name,
69
- })));
61
+ const inputs = (0, data_type_schema_1.SchemaToDataType)(options.inputs);
62
+ const outputs = (0, data_type_schema_1.SchemaToDataType)(options.outputs);
70
63
  return {
71
64
  id: options.id || options.name || (0, nanoid_1.nanoid)(),
72
65
  name: options.name,
@@ -22,6 +22,7 @@ const lodash_1 = require("lodash");
22
22
  const nanoid_1 = require("nanoid");
23
23
  const tsyringe_1 = require("tsyringe");
24
24
  const constants_1 = require("./constants");
25
+ const data_type_schema_1 = require("./data-type-schema");
25
26
  const logger_1 = __importDefault(require("./logger"));
26
27
  const runnable_1 = require("./runnable");
27
28
  const utils_1 = require("./utils");
@@ -145,11 +146,7 @@ exports.PipelineAgent = PipelineAgent = PipelineAgent_1 = __decorate([
145
146
  __metadata("design:paramtypes", [Object, Object])
146
147
  ], PipelineAgent);
147
148
  function createPipelineAgentDefinition(options) {
148
- const inputs = ordered_map_1.OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
149
- ...dataType,
150
- id: (0, nanoid_1.nanoid)(),
151
- name,
152
- })));
149
+ const inputs = (0, data_type_schema_1.SchemaToDataType)(options.inputs);
153
150
  const processes = ordered_map_1.OrderedRecord.fromArray([]);
154
151
  for (const p of options.processes || []) {
155
152
  ordered_map_1.OrderedRecord.push(processes, {
@@ -180,18 +177,13 @@ function createPipelineAgentDefinition(options) {
180
177
  }).filter(is_non_nullable_1.isNonNullable)),
181
178
  });
182
179
  }
183
- const outputs = ordered_map_1.OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { fromVariable, ...output }]) => {
180
+ const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0, data_type_schema_1.SchemaToDataType)(options.outputs), (output) => {
181
+ const { fromVariable, fromVariablePropPath } = options.outputs[output.name];
184
182
  const from = ordered_map_1.OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
185
183
  ordered_map_1.OrderedRecord.find(processes, (p) => p.name === fromVariable);
186
184
  if (!from)
187
185
  throw new Error(`Output ${name} not found in inputs or processes`);
188
- return {
189
- ...output,
190
- id: (0, nanoid_1.nanoid)(),
191
- name,
192
- from: 'variable',
193
- fromVariableId: from.id,
194
- };
186
+ return { ...output, from: 'variable', fromVariableId: from.id, fromVariablePropPath };
195
187
  }));
196
188
  return {
197
189
  id: options.id || options.name || (0, nanoid_1.nanoid)(),