@alpic80/rivet-core 1.24.0-aidon.3 → 1.24.0-aidon.4

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.
@@ -21885,6 +21885,7 @@ var dotProductSimilarity = (a, b) => {
21885
21885
  async function* getProcessorEvents(processor, spec) {
21886
21886
  var _a, _b, _c, _d, _e, _f;
21887
21887
  const previousIndexes = /* @__PURE__ */ new Map();
21888
+ const usages = [];
21888
21889
  for await (const event of processor.events()) {
21889
21890
  if (event.type === "partialOutput") {
21890
21891
  if (spec.partialOutputs === true || ((_a = spec.partialOutputs) == null ? void 0 : _a.includes(event.node.id)) || ((_b = spec.partialOutputs) == null ? void 0 : _b.includes(event.node.title))) {
@@ -21900,9 +21901,26 @@ async function* getProcessorEvents(processor, spec) {
21900
21901
  }
21901
21902
  } else if (event.type === "done") {
21902
21903
  if (spec.done) {
21904
+ const results = event.results;
21905
+ if (!spec.exposeCost) {
21906
+ delete results.cost;
21907
+ }
21908
+ if (!spec.exposeUsage) {
21909
+ delete results.requestTokens;
21910
+ delete results.responseTokens;
21911
+ } else if (usages.length) {
21912
+ const usageOutput = {
21913
+ type: "any[]",
21914
+ value: usages
21915
+ };
21916
+ results["usages"] = usageOutput;
21917
+ }
21918
+ if (spec.removeFinalOutput) {
21919
+ delete results.output;
21920
+ }
21903
21921
  yield {
21904
21922
  type: "done",
21905
- graphOutput: event.results
21923
+ graphOutput: results
21906
21924
  };
21907
21925
  }
21908
21926
  } else if (event.type === "error") {
@@ -21922,6 +21940,12 @@ async function* getProcessorEvents(processor, spec) {
21922
21940
  };
21923
21941
  }
21924
21942
  } else if (event.type === "nodeFinish") {
21943
+ if (spec.exposeUsage) {
21944
+ const usage = event.outputs["usage"];
21945
+ if (usage !== void 0) {
21946
+ usages.push(usage);
21947
+ }
21948
+ }
21925
21949
  if (spec.nodeFinish === true || ((_e = spec.nodeFinish) == null ? void 0 : _e.includes(event.node.id)) || ((_f = spec.nodeFinish) == null ? void 0 : _f.includes(event.node.title))) {
21926
21950
  yield {
21927
21951
  type: "nodeFinish",
@@ -21955,19 +21979,47 @@ data: ${JSON.stringify(data)}
21955
21979
  }
21956
21980
  });
21957
21981
  }
21958
- function getSingleNodeStream(processor, nodeIdOrTitle) {
21982
+ function getSingleNodeStream(processor, arg) {
21983
+ let spec;
21984
+ if (typeof arg === "string") {
21985
+ const nodeIdOrTitle = arg;
21986
+ spec = {
21987
+ partialOutputs: [nodeIdOrTitle],
21988
+ nodeFinish: [nodeIdOrTitle]
21989
+ };
21990
+ } else {
21991
+ spec = arg;
21992
+ }
21959
21993
  return new ReadableStream({
21960
21994
  async start(controller) {
21961
21995
  try {
21962
- for await (const event of getProcessorEvents(processor, {
21963
- partialOutputs: [nodeIdOrTitle],
21964
- nodeFinish: [nodeIdOrTitle]
21965
- })) {
21966
- if (event.type === "partialOutput" && (event.nodeId === nodeIdOrTitle || event.nodeTitle === nodeIdOrTitle)) {
21996
+ for await (const event of getProcessorEvents(processor, spec)) {
21997
+ if (event.type === "partialOutput") {
21967
21998
  controller.enqueue(`data: ${JSON.stringify(event.delta)}
21968
21999
 
21969
22000
  `);
21970
- } else if (event.type === "nodeFinish" && (event.nodeId === nodeIdOrTitle || event.nodeTitle === nodeIdOrTitle)) {
22001
+ } else if (event.type === "error") {
22002
+ controller.enqueue(`error: ${JSON.stringify(event.error)}
22003
+
22004
+ `);
22005
+ } else if (event.type === "done") {
22006
+ if (spec.done) {
22007
+ const results = event.graphOutput;
22008
+ if (!spec.exposeCost) {
22009
+ delete results.cost;
22010
+ }
22011
+ if (!spec.exposeUsage) {
22012
+ delete results.requestTokens;
22013
+ delete results.responseTokens;
22014
+ delete results.usages;
22015
+ }
22016
+ if (spec.removeFinalOutput) {
22017
+ delete results.output;
22018
+ }
22019
+ controller.enqueue(`graphOutput: ${JSON.stringify(results)}
22020
+
22021
+ `);
22022
+ }
21971
22023
  controller.close();
21972
22024
  }
21973
22025
  }