@aigne/core 0.4.199 → 0.4.201-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.
@@ -15,7 +15,7 @@ import { nanoid } from 'nanoid';
15
15
  import { inject, injectable } from 'tsyringe';
16
16
  import { TYPES } from './constants';
17
17
  import { FunctionRunner } from './function-runner';
18
- import { Runnable, } from './runnable';
18
+ import { Runnable } from './runnable';
19
19
  import { OrderedRecord, objectToRunnableResponseStream } from './utils';
20
20
  let FunctionAgent = FunctionAgent_1 = class FunctionAgent extends Runnable {
21
21
  definition;
@@ -53,24 +53,20 @@ FunctionAgent = FunctionAgent_1 = __decorate([
53
53
  ], FunctionAgent);
54
54
  export { FunctionAgent };
55
55
  export function createFunctionAgentDefinition(options) {
56
- const inputs = OrderedRecord.fromArray(options.inputs?.map((i) => ({
57
- id: nanoid(),
58
- name: i.name,
59
- type: i.type,
60
- required: i.required,
61
- })));
62
- const outputs = OrderedRecord.fromArray(options.outputs?.map((i) => ({
63
- id: nanoid(),
64
- name: i.name,
65
- type: i.type,
66
- required: i.required,
67
- })));
68
56
  return {
69
57
  id: options.id || options.name || nanoid(),
70
58
  name: options.name,
71
59
  type: 'function_agent',
72
- inputs,
73
- outputs,
60
+ inputs: OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
61
+ ...dataType,
62
+ id: nanoid(),
63
+ name,
64
+ }))),
65
+ outputs: OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { ...dataType }]) => ({
66
+ ...dataType,
67
+ id: nanoid(),
68
+ name,
69
+ }))),
74
70
  language: options.language,
75
71
  code: options.code,
76
72
  };
@@ -108,26 +108,26 @@ LLMAgent = LLMAgent_1 = __decorate([
108
108
  ], LLMAgent);
109
109
  export { LLMAgent };
110
110
  export function createLLMAgentDefinition(options) {
111
- const inputs = OrderedRecord.fromArray(options.inputs?.map((i) => ({
112
- id: nanoid(),
113
- name: i.name,
114
- type: i.type,
115
- required: i.required,
116
- })));
117
- const outputs = OrderedRecord.fromArray(options.outputs?.map((i) => ({ ...i, id: nanoid() })));
118
- const messages = OrderedRecord.fromArray(options.messages?.map((i) => ({
119
- id: nanoid(),
120
- role: i.role,
121
- content: i.content,
122
- })));
123
111
  return {
124
112
  id: options.id || options.name || nanoid(),
125
113
  name: options.name,
126
114
  type: 'llm_agent',
127
- inputs,
128
- outputs,
129
- messages,
115
+ inputs: OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
116
+ ...dataType,
117
+ id: nanoid(),
118
+ name,
119
+ }))),
120
+ outputs: OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { ...dataType }]) => ({
121
+ ...dataType,
122
+ id: nanoid(),
123
+ name,
124
+ }))),
130
125
  modelOptions: options.modelOptions,
126
+ messages: OrderedRecord.fromArray(options.messages?.map((i) => ({
127
+ id: nanoid(),
128
+ role: i.role,
129
+ content: i.content,
130
+ }))),
131
131
  };
132
132
  }
133
133
  function outputsToJsonSchema(outputs) {
@@ -110,11 +110,10 @@ LLMDecisionAgent = LLMDecisionAgent_1 = __decorate([
110
110
  ], LLMDecisionAgent);
111
111
  export { LLMDecisionAgent };
112
112
  export function createLLMDecisionAgentDefinition(options) {
113
- const inputs = OrderedRecord.fromArray(options.inputs?.map((i) => ({
113
+ const inputs = OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
114
+ ...dataType,
114
115
  id: nanoid(),
115
- name: i.name,
116
- type: i.type,
117
- required: i.required,
116
+ name: name,
118
117
  })));
119
118
  const messages = OrderedRecord.fromArray([
120
119
  {
@@ -53,17 +53,15 @@ LocalFunctionAgent = LocalFunctionAgent_1 = __decorate([
53
53
  ], LocalFunctionAgent);
54
54
  export { LocalFunctionAgent };
55
55
  export function createLocalFunctionAgentDefinition(options) {
56
- const inputs = OrderedRecord.fromArray(options.inputs?.map((i) => ({
56
+ const inputs = OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, i]) => ({
57
+ ...i,
57
58
  id: nanoid(),
58
- name: i.name,
59
- type: i.type,
60
- required: i.required,
59
+ name,
61
60
  })));
62
- const outputs = OrderedRecord.fromArray(options.outputs?.map((i) => ({
61
+ const outputs = OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, o]) => ({
62
+ ...o,
63
63
  id: nanoid(),
64
- name: i.name,
65
- type: i.type,
66
- required: i.required,
64
+ name,
67
65
  })));
68
66
  return {
69
67
  id: options.id || options.name || nanoid(),
@@ -138,11 +138,10 @@ PipelineAgent = PipelineAgent_1 = __decorate([
138
138
  ], PipelineAgent);
139
139
  export { PipelineAgent };
140
140
  export function createPipelineAgentDefinition(options) {
141
- const inputs = OrderedRecord.fromArray(options.inputs?.map((i) => ({
141
+ const inputs = OrderedRecord.fromArray(Object.entries(options.inputs).map(([name, { ...dataType }]) => ({
142
+ ...dataType,
142
143
  id: nanoid(),
143
- name: i.name,
144
- type: i.type,
145
- required: i.required,
144
+ name,
146
145
  })));
147
146
  const processes = OrderedRecord.fromArray([]);
148
147
  for (const p of options.processes || []) {
@@ -174,19 +173,17 @@ export function createPipelineAgentDefinition(options) {
174
173
  }).filter(isNonNullable)),
175
174
  });
176
175
  }
177
- const outputs = OrderedRecord.fromArray(options.outputs.map((output) => {
178
- const from = OrderedRecord.find(inputs, (i) => i.name === output.fromVariable) ||
179
- OrderedRecord.find(processes, (p) => p.name === output.fromVariable);
176
+ const outputs = OrderedRecord.fromArray(Object.entries(options.outputs).map(([name, { fromVariable, ...output }]) => {
177
+ const from = OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
178
+ OrderedRecord.find(processes, (p) => p.name === fromVariable);
180
179
  if (!from)
181
- throw new Error(`Output ${output.name} not found in inputs or processes`);
180
+ throw new Error(`Output ${name} not found in inputs or processes`);
182
181
  return {
182
+ ...output,
183
183
  id: nanoid(),
184
- name: output.name,
185
- type: output.type,
186
- required: output.required,
184
+ name,
187
185
  from: 'variable',
188
186
  fromVariableId: from.id,
189
- fromVariablePropPath: output.fromVariablePropPath,
190
187
  };
191
188
  }));
192
189
  return {