@aigne/core 0.4.197 → 0.4.198

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.
@@ -99,7 +99,7 @@ let LLMAgent = LLMAgent_1 = class LLMAgent extends runnable_1.Runnable {
99
99
  }
100
100
  const text = textOutput ? await model.run(llmInputs) : undefined;
101
101
  return {
102
- $text: text,
102
+ $text: text?.$text,
103
103
  ...(await jsonOutput),
104
104
  };
105
105
  }
@@ -87,29 +87,37 @@ let PipelineAgent = PipelineAgent_1 = class PipelineAgent extends runnable_1.Run
87
87
  .filter(is_non_nullable_1.isNonNullable));
88
88
  const stream = await runnable.run(inputValues, { stream: true });
89
89
  const needRespondTextStream = textStreamOutput?.from === 'variable' && textStreamOutput.fromVariableId === process.id;
90
- const needRespondJsonStream = outputs.some((i) => i.name !== constants_1.StreamTextOutputName && i.from === 'variable' && i.fromVariableId === process.id);
90
+ // const needRespondJsonStream = outputs.some(
91
+ // (i) => i.name !== StreamTextOutputName && i.from === 'variable' && i.fromVariableId === process.id
92
+ // );
93
+ const processResult = {};
94
+ variables[process.id] = processResult;
91
95
  for await (const chunk of stream) {
92
- if (chunk.$text && needRespondTextStream) {
93
- controller.enqueue({ $text: chunk.$text });
96
+ if (chunk.$text) {
97
+ Object.assign(processResult, { $text: (processResult.$text || '') + chunk.$text });
98
+ if (needRespondTextStream) {
99
+ controller.enqueue({ $text: chunk.$text });
100
+ }
94
101
  }
95
102
  if (chunk.delta) {
96
- variables[process.id] = chunk.delta;
97
- if (needRespondJsonStream) {
98
- result = Object.fromEntries(ordered_map_1.OrderedRecord.map(definition.outputs, (output) => {
99
- if (!output.name)
100
- return null;
101
- let value;
102
- if (output.from === 'variable') {
103
- const v = variables[output.fromVariableId];
104
- value = output.fromVariablePropPath?.length ? (0, lodash_1.get)(v, output.fromVariablePropPath) : v;
105
- }
106
- else {
107
- throw new Error(`Unsupported output source ${output.from}`);
108
- }
109
- return [output.name, value];
110
- }).filter(is_non_nullable_1.isNonNullable));
111
- controller.enqueue({ delta: result });
112
- }
103
+ Object.assign(processResult, chunk.delta);
104
+ // TODO: 这里需要考虑上层 agent 直接输出了 {$text: 'xxx'} 没有用 chunk 的方式返回的情况
105
+ // if (needRespondJsonStream) {
106
+ result = Object.fromEntries(ordered_map_1.OrderedRecord.map(definition.outputs, (output) => {
107
+ if (!output.name)
108
+ return null;
109
+ let value;
110
+ if (output.from === 'variable') {
111
+ const v = variables[output.fromVariableId];
112
+ value = output.fromVariablePropPath?.length ? (0, lodash_1.get)(v, output.fromVariablePropPath) : v;
113
+ }
114
+ else {
115
+ throw new Error(`Unsupported output source ${output.from}`);
116
+ }
117
+ return [output.name, value];
118
+ }).filter(is_non_nullable_1.isNonNullable));
119
+ controller.enqueue({ delta: result });
120
+ // }
113
121
  }
114
122
  }
115
123
  }