@aigne/core 0.4.201-5 → 0.4.201-7
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/lib/cjs/data-type-schema.js +14 -19
- package/lib/cjs/function-agent.js +2 -2
- package/lib/cjs/llm-agent.js +2 -2
- package/lib/cjs/llm-decision-agent.js +3 -46
- package/lib/cjs/local-function-agent.js +2 -2
- package/lib/cjs/pipeline-agent.js +2 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/ordered-map.js +7 -0
- package/lib/cjs/utils/runnable-type.js +2 -0
- package/lib/cjs/utils/union.js +2 -0
- package/lib/esm/data-type-schema.js +13 -18
- package/lib/esm/function-agent.js +3 -3
- package/lib/esm/llm-agent.js +3 -3
- package/lib/esm/llm-decision-agent.js +5 -48
- package/lib/esm/local-function-agent.js +3 -3
- package/lib/esm/pipeline-agent.js +3 -3
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/ordered-map.js +7 -0
- package/lib/esm/utils/runnable-type.js +1 -0
- package/lib/esm/utils/union.js +1 -0
- package/lib/types/data-type-schema.d.ts +2 -1
- package/lib/types/llm-decision-agent.d.ts +6 -12
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/ordered-map.d.ts +3 -0
- package/lib/types/utils/runnable-type.d.ts +3 -0
- package/lib/types/utils/union.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,47 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.schemaToDataType = schemaToDataType;
|
|
4
4
|
const nanoid_1 = require("nanoid");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
function
|
|
6
|
+
function schemaToDataType(dataType) {
|
|
7
7
|
return utils_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
|
|
8
|
+
const base = {
|
|
9
|
+
...schema,
|
|
10
|
+
id: (0, nanoid_1.nanoid)(),
|
|
11
|
+
name,
|
|
12
|
+
};
|
|
8
13
|
switch (schema.type) {
|
|
9
14
|
case 'string':
|
|
10
15
|
return {
|
|
11
|
-
|
|
12
|
-
name,
|
|
16
|
+
...base,
|
|
13
17
|
type: 'string',
|
|
14
|
-
required: schema.required,
|
|
15
18
|
};
|
|
16
19
|
case 'number':
|
|
17
20
|
return {
|
|
18
|
-
|
|
19
|
-
name,
|
|
21
|
+
...base,
|
|
20
22
|
type: 'number',
|
|
21
|
-
required: schema.required,
|
|
22
23
|
};
|
|
23
24
|
case 'boolean':
|
|
24
25
|
return {
|
|
25
|
-
|
|
26
|
-
name,
|
|
26
|
+
...base,
|
|
27
27
|
type: 'boolean',
|
|
28
|
-
required: schema.required,
|
|
29
28
|
};
|
|
30
29
|
case 'object':
|
|
31
30
|
return {
|
|
32
|
-
|
|
33
|
-
name,
|
|
31
|
+
...base,
|
|
34
32
|
type: 'object',
|
|
35
|
-
|
|
36
|
-
properties: SchemaToDataType(schema.properties),
|
|
33
|
+
properties: schemaToDataType(schema.properties),
|
|
37
34
|
};
|
|
38
35
|
case 'array':
|
|
39
36
|
return {
|
|
40
|
-
|
|
41
|
-
name,
|
|
37
|
+
...base,
|
|
42
38
|
type: 'array',
|
|
43
|
-
|
|
44
|
-
items: SchemaToDataType({ items: schema.items })['items'],
|
|
39
|
+
items: utils_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === 'items'),
|
|
45
40
|
};
|
|
46
41
|
default: {
|
|
47
42
|
throw new Error(`Unknown data type: ${schema.type}`);
|
|
@@ -62,8 +62,8 @@ function createFunctionAgentDefinition(options) {
|
|
|
62
62
|
id: options.id || options.name || (0, nanoid_1.nanoid)(),
|
|
63
63
|
name: options.name,
|
|
64
64
|
type: 'function_agent',
|
|
65
|
-
inputs: (0, data_type_schema_1.
|
|
66
|
-
outputs: (0, data_type_schema_1.
|
|
65
|
+
inputs: (0, data_type_schema_1.schemaToDataType)(options.inputs),
|
|
66
|
+
outputs: (0, data_type_schema_1.schemaToDataType)(options.outputs),
|
|
67
67
|
language: options.language,
|
|
68
68
|
code: options.code,
|
|
69
69
|
};
|
package/lib/cjs/llm-agent.js
CHANGED
|
@@ -117,8 +117,8 @@ function createLLMAgentDefinition(options) {
|
|
|
117
117
|
id: options.id || options.name || (0, nanoid_1.nanoid)(),
|
|
118
118
|
name: options.name,
|
|
119
119
|
type: 'llm_agent',
|
|
120
|
-
inputs: (0, data_type_schema_1.
|
|
121
|
-
outputs: (0, data_type_schema_1.
|
|
120
|
+
inputs: (0, data_type_schema_1.schemaToDataType)(options.inputs),
|
|
121
|
+
outputs: (0, data_type_schema_1.schemaToDataType)(options.outputs),
|
|
122
122
|
modelOptions: options.modelOptions,
|
|
123
123
|
messages: ordered_map_1.OrderedRecord.fromArray(options.messages?.map((i) => ({
|
|
124
124
|
id: (0, nanoid_1.nanoid)(),
|
|
@@ -15,11 +15,9 @@ var LLMDecisionAgent_1;
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.LLMDecisionAgent = void 0;
|
|
17
17
|
exports.createLLMDecisionAgentDefinition = createLLMDecisionAgentDefinition;
|
|
18
|
-
const lodash_1 = require("lodash");
|
|
19
18
|
const nanoid_1 = require("nanoid");
|
|
20
19
|
const tsyringe_1 = require("tsyringe");
|
|
21
20
|
const constants_1 = require("./constants");
|
|
22
|
-
const data_type_schema_1 = require("./data-type-schema");
|
|
23
21
|
const llm_model_1 = require("./llm-model");
|
|
24
22
|
const runnable_1 = require("./runnable");
|
|
25
23
|
const utils_1 = require("./utils");
|
|
@@ -83,27 +81,8 @@ let LLMDecisionAgent = LLMDecisionAgent_1 = class LLMDecisionAgent extends runna
|
|
|
83
81
|
const caseToCall = cases.find((i) => i.name === functionNameToCall);
|
|
84
82
|
if (!caseToCall)
|
|
85
83
|
throw new Error('Case not found');
|
|
86
|
-
// NOTE: 将 input 转换为 variables,其中 key 为 inputId,value 为 input 的值
|
|
87
|
-
const variables = Object.fromEntries(utils_1.OrderedRecord.map(this.definition.inputs, (i) => {
|
|
88
|
-
const value = input[i.name || i.id];
|
|
89
|
-
if ((0, lodash_1.isNil)(value))
|
|
90
|
-
return null;
|
|
91
|
-
return [i.id, value];
|
|
92
|
-
}).filter(utils_1.isNonNullable));
|
|
93
|
-
const inputForCase = Object.fromEntries(Object.entries(caseToCall.input ?? {})
|
|
94
|
-
.map(([inputId, { from, fromVariableId, fromVariablePropPath }]) => {
|
|
95
|
-
const targetInput = utils_1.OrderedRecord.find(caseToCall.runnable.definition.inputs, (i) => i.id === inputId);
|
|
96
|
-
if (!targetInput?.name)
|
|
97
|
-
return null;
|
|
98
|
-
if (from !== 'variable' || !fromVariableId)
|
|
99
|
-
return null;
|
|
100
|
-
const v = variables[fromVariableId];
|
|
101
|
-
const value = fromVariablePropPath?.length ? (0, lodash_1.get)(v, fromVariablePropPath) : v;
|
|
102
|
-
return [targetInput.name, value];
|
|
103
|
-
})
|
|
104
|
-
.filter(utils_1.isNonNullable));
|
|
105
84
|
// TODO: check result structure and omit undefined values
|
|
106
|
-
return (await caseToCall.runnable.run(
|
|
85
|
+
return (await caseToCall.runnable.run(input, options));
|
|
107
86
|
}
|
|
108
87
|
};
|
|
109
88
|
exports.LLMDecisionAgent = LLMDecisionAgent;
|
|
@@ -115,7 +94,6 @@ exports.LLMDecisionAgent = LLMDecisionAgent = LLMDecisionAgent_1 = __decorate([
|
|
|
115
94
|
__metadata("design:paramtypes", [Object, llm_model_1.LLMModel, Object])
|
|
116
95
|
], LLMDecisionAgent);
|
|
117
96
|
function createLLMDecisionAgentDefinition(options) {
|
|
118
|
-
const inputs = (0, data_type_schema_1.SchemaToDataType)(options.inputs);
|
|
119
97
|
const messages = utils_1.OrderedRecord.fromArray([
|
|
120
98
|
{
|
|
121
99
|
id: (0, nanoid_1.nanoid)(),
|
|
@@ -128,34 +106,13 @@ function createLLMDecisionAgentDefinition(options) {
|
|
|
128
106
|
name: c.name || c.runnable.name,
|
|
129
107
|
description: c.description,
|
|
130
108
|
runnable: { id: c.runnable.id },
|
|
131
|
-
// TODO: pass input from decision to case runnable
|
|
132
|
-
input: Object.fromEntries(utils_1.OrderedRecord.map(c.runnable.definition.inputs, (inputOfCase) => {
|
|
133
|
-
const i = c.input?.[inputOfCase.name || inputOfCase.id];
|
|
134
|
-
if (!i) {
|
|
135
|
-
if (inputOfCase.required) {
|
|
136
|
-
throw new Error(`Input ${inputOfCase.name || inputOfCase.id} for case ${c.runnable.name || c.runnable.id} is required`);
|
|
137
|
-
}
|
|
138
|
-
// ignore optional input
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const inputFromDecision = utils_1.OrderedRecord.find(inputs, (input) => input.name === i.fromVariable);
|
|
142
|
-
if (!inputFromDecision)
|
|
143
|
-
throw new Error(`Input ${i.fromVariable} not found`);
|
|
144
|
-
return [
|
|
145
|
-
inputOfCase.id,
|
|
146
|
-
{
|
|
147
|
-
from: 'variable',
|
|
148
|
-
fromVariableId: inputFromDecision.id,
|
|
149
|
-
fromVariablePropPath: i.fromVariablePropPath,
|
|
150
|
-
},
|
|
151
|
-
];
|
|
152
|
-
}).filter(utils_1.isNonNullable)),
|
|
153
109
|
})));
|
|
154
110
|
return {
|
|
155
111
|
id: options.id || options.name || (0, nanoid_1.nanoid)(),
|
|
156
112
|
name: options.name,
|
|
157
113
|
type: 'llm_decision_agent',
|
|
158
|
-
inputs
|
|
114
|
+
// TODO: decision agent inputs should be the intersection of all case inputs
|
|
115
|
+
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
159
116
|
// TODO: decision agent outputs should be the union of all case outputs
|
|
160
117
|
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
161
118
|
messages,
|
|
@@ -58,8 +58,8 @@ exports.LocalFunctionAgent = LocalFunctionAgent = LocalFunctionAgent_1 = __decor
|
|
|
58
58
|
__metadata("design:paramtypes", [Object, Object])
|
|
59
59
|
], LocalFunctionAgent);
|
|
60
60
|
function createLocalFunctionAgentDefinition(options) {
|
|
61
|
-
const inputs = (0, data_type_schema_1.
|
|
62
|
-
const outputs = (0, data_type_schema_1.
|
|
61
|
+
const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
|
|
62
|
+
const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
|
|
63
63
|
return {
|
|
64
64
|
id: options.id || options.name || (0, nanoid_1.nanoid)(),
|
|
65
65
|
name: options.name,
|
|
@@ -146,7 +146,7 @@ exports.PipelineAgent = PipelineAgent = PipelineAgent_1 = __decorate([
|
|
|
146
146
|
__metadata("design:paramtypes", [Object, Object])
|
|
147
147
|
], PipelineAgent);
|
|
148
148
|
function createPipelineAgentDefinition(options) {
|
|
149
|
-
const inputs = (0, data_type_schema_1.
|
|
149
|
+
const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
|
|
150
150
|
const processes = ordered_map_1.OrderedRecord.fromArray([]);
|
|
151
151
|
for (const p of options.processes || []) {
|
|
152
152
|
ordered_map_1.OrderedRecord.push(processes, {
|
|
@@ -177,7 +177,7 @@ function createPipelineAgentDefinition(options) {
|
|
|
177
177
|
}).filter(is_non_nullable_1.isNonNullable)),
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0, data_type_schema_1.
|
|
180
|
+
const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0, data_type_schema_1.schemaToDataType)(options.outputs), (output) => {
|
|
181
181
|
const { fromVariable, fromVariablePropPath } = options.outputs[output.name];
|
|
182
182
|
const from = ordered_map_1.OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
|
|
183
183
|
ordered_map_1.OrderedRecord.find(processes, (p) => p.name === fromVariable);
|