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