@alpic80/rivet-core 1.24.2-aidon.1 → 1.24.2-aidon.3

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.
@@ -22971,11 +22971,13 @@ function nodeMatches(spec, event) {
22971
22971
  async function* getProcessorEvents(processor, spec) {
22972
22972
  const previousIndexes = /* @__PURE__ */ new Map();
22973
22973
  const usages = [];
22974
+ let hasDelta = false;
22974
22975
  for await (const event of processor.events()) {
22975
22976
  if (event.type === "partialOutput") {
22976
22977
  if (spec.partialOutputs === true || nodeMatches(spec.partialOutputs, event)) {
22977
22978
  const currentOutput = coerceType(event.outputs["response"], "string");
22978
22979
  const delta = currentOutput.slice(previousIndexes.get(event.node.id) ?? 0);
22980
+ hasDelta = true;
22979
22981
  yield {
22980
22982
  type: "partialOutput",
22981
22983
  nodeId: event.node.id,
@@ -23031,7 +23033,7 @@ async function* getProcessorEvents(processor, spec) {
23031
23033
  usages.push(usage);
23032
23034
  }
23033
23035
  }
23034
- if (spec.nodeFinish === true || nodeMatches(spec.nodeFinish, event)) {
23036
+ if ((spec.nodeFinish === true || nodeMatches(spec.nodeFinish, event)) && !(spec.removeFinalOutput && hasDelta)) {
23035
23037
  yield {
23036
23038
  type: "nodeFinish",
23037
23039
  outputs: event.outputs,
@@ -23071,10 +23073,11 @@ data: ${JSON.stringify(data)}
23071
23073
  return new ReadableStream({
23072
23074
  async start(controller) {
23073
23075
  const userEventHandler = async (eventName, data) => {
23074
- sendEvent(controller, "event", {
23076
+ const graphEvent = {
23075
23077
  name: eventName,
23076
23078
  message: coerceType(data, "string")
23077
- });
23079
+ };
23080
+ sendEvent(controller, "event", { graphEvent });
23078
23081
  };
23079
23082
  const streamEvents = createOnStreamUserEvents(spec.userStreamEvents, userEventHandler);
23080
23083
  if (streamEvents) {
@@ -23108,6 +23111,21 @@ function getSingleNodeStream(processor, arg) {
23108
23111
  async start(controller) {
23109
23112
  var _a;
23110
23113
  try {
23114
+ const userEventHandler = async (eventName, data) => {
23115
+ const payload = {
23116
+ name: eventName,
23117
+ message: coerceType(data, "string")
23118
+ };
23119
+ controller.enqueue(`event: ${JSON.stringify(payload)}
23120
+
23121
+ `);
23122
+ };
23123
+ const streamEvents = createOnStreamUserEvents(spec.userStreamEvents, userEventHandler);
23124
+ if (streamEvents) {
23125
+ for (const [name, fn] of Object.entries(streamEvents)) {
23126
+ processor.onUserEvent(name, fn);
23127
+ }
23128
+ }
23111
23129
  for await (const event of getProcessorEvents(processor, spec)) {
23112
23130
  if (event.type === "partialOutput") {
23113
23131
  controller.enqueue(`data: ${JSON.stringify(event.delta)}