@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.
|
@@ -3,6 +3,7 @@ import { coerceType } from '../utils/coerceType.js';
|
|
|
3
3
|
/** A simplified way to listen and stream processor events, including filtering. */
|
|
4
4
|
export async function* getProcessorEvents(processor, spec) {
|
|
5
5
|
const previousIndexes = new Map();
|
|
6
|
+
const usages = [];
|
|
6
7
|
for await (const event of processor.events()) {
|
|
7
8
|
if (event.type === 'partialOutput') {
|
|
8
9
|
if (spec.partialOutputs === true ||
|
|
@@ -21,9 +22,27 @@ export async function* getProcessorEvents(processor, spec) {
|
|
|
21
22
|
}
|
|
22
23
|
else if (event.type === 'done') {
|
|
23
24
|
if (spec.done) {
|
|
25
|
+
const results = event.results;
|
|
26
|
+
if (!spec.exposeCost) {
|
|
27
|
+
delete results.cost;
|
|
28
|
+
}
|
|
29
|
+
if (!spec.exposeUsage) {
|
|
30
|
+
delete results.requestTokens;
|
|
31
|
+
delete results.responseTokens;
|
|
32
|
+
}
|
|
33
|
+
else if (usages.length) {
|
|
34
|
+
const usageOutput = {
|
|
35
|
+
type: 'any[]',
|
|
36
|
+
value: usages
|
|
37
|
+
};
|
|
38
|
+
results['usages'] = usageOutput;
|
|
39
|
+
}
|
|
40
|
+
if (spec.removeFinalOutput) {
|
|
41
|
+
delete results.output;
|
|
42
|
+
}
|
|
24
43
|
yield {
|
|
25
44
|
type: 'done',
|
|
26
|
-
graphOutput:
|
|
45
|
+
graphOutput: results,
|
|
27
46
|
};
|
|
28
47
|
}
|
|
29
48
|
}
|
|
@@ -48,6 +67,12 @@ export async function* getProcessorEvents(processor, spec) {
|
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
else if (event.type === 'nodeFinish') {
|
|
70
|
+
if (spec.exposeUsage) {
|
|
71
|
+
const usage = event.outputs['usage'];
|
|
72
|
+
if (usage !== undefined) {
|
|
73
|
+
usages.push(usage);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
51
76
|
if (spec.nodeFinish === true ||
|
|
52
77
|
spec.nodeFinish?.includes(event.node.id) ||
|
|
53
78
|
spec.nodeFinish?.includes(event.node.title)) {
|
|
@@ -90,19 +115,44 @@ spec) {
|
|
|
90
115
|
},
|
|
91
116
|
});
|
|
92
117
|
}
|
|
93
|
-
export function getSingleNodeStream(processor,
|
|
118
|
+
export function getSingleNodeStream(processor, arg) {
|
|
119
|
+
let spec;
|
|
120
|
+
if (typeof arg === 'string') {
|
|
121
|
+
const nodeIdOrTitle = arg;
|
|
122
|
+
spec = {
|
|
123
|
+
partialOutputs: [nodeIdOrTitle],
|
|
124
|
+
nodeFinish: [nodeIdOrTitle],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
spec = arg;
|
|
129
|
+
}
|
|
94
130
|
return new ReadableStream({
|
|
95
131
|
async start(controller) {
|
|
96
132
|
try {
|
|
97
|
-
for await (const event of getProcessorEvents(processor, {
|
|
98
|
-
|
|
99
|
-
nodeFinish: [nodeIdOrTitle],
|
|
100
|
-
})) {
|
|
101
|
-
if (event.type === 'partialOutput' && (event.nodeId === nodeIdOrTitle || event.nodeTitle === nodeIdOrTitle)) {
|
|
133
|
+
for await (const event of getProcessorEvents(processor, spec)) {
|
|
134
|
+
if (event.type === 'partialOutput') { //nodeIdOrTitle filter managed by spec
|
|
102
135
|
controller.enqueue(`data: ${JSON.stringify(event.delta)}\n\n`);
|
|
103
136
|
}
|
|
104
|
-
else if (event.type === '
|
|
105
|
-
(
|
|
137
|
+
else if (event.type === 'error') {
|
|
138
|
+
controller.enqueue(`error: ${JSON.stringify(event.error)}\n\n`);
|
|
139
|
+
}
|
|
140
|
+
else if (event.type === 'done') {
|
|
141
|
+
if (spec.done) {
|
|
142
|
+
const results = event.graphOutput;
|
|
143
|
+
if (!spec.exposeCost) {
|
|
144
|
+
delete results.cost;
|
|
145
|
+
}
|
|
146
|
+
if (!spec.exposeUsage) {
|
|
147
|
+
delete results.requestTokens;
|
|
148
|
+
delete results.responseTokens;
|
|
149
|
+
delete results.usages;
|
|
150
|
+
}
|
|
151
|
+
if (spec.removeFinalOutput) {
|
|
152
|
+
delete results.output;
|
|
153
|
+
}
|
|
154
|
+
controller.enqueue(`graphOutput: ${JSON.stringify(results)}\n\n`);
|
|
155
|
+
}
|
|
106
156
|
controller.close();
|
|
107
157
|
}
|
|
108
158
|
}
|
|
@@ -6,6 +6,12 @@ export type RivetEventStreamFilterSpec = {
|
|
|
6
6
|
done?: boolean;
|
|
7
7
|
/** If the graph errors, send an error event? */
|
|
8
8
|
error?: boolean;
|
|
9
|
+
/** Expose the cost of the graph run in the response */
|
|
10
|
+
exposeCost?: boolean;
|
|
11
|
+
/** Expose the token usage of the graph run in the response */
|
|
12
|
+
exposeUsage?: boolean;
|
|
13
|
+
/** Whether to remove the final output when done is true */
|
|
14
|
+
removeFinalOutput?: boolean;
|
|
9
15
|
/** Stream node start events for the specified node IDs or node titles. */
|
|
10
16
|
nodeStart?: string[] | true;
|
|
11
17
|
/** Stream node finish events for the specified nodeIDs or node titles. */
|
|
@@ -54,3 +60,4 @@ export declare function getProcessorSSEStream(processor: GraphProcessor,
|
|
|
54
60
|
/** The spec for what you're streaming to the client */
|
|
55
61
|
spec: RivetEventStreamFilterSpec): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
56
62
|
export declare function getSingleNodeStream(processor: GraphProcessor, nodeIdOrTitle: string): ReadableStream<string>;
|
|
63
|
+
export declare function getSingleNodeStream(processor: GraphProcessor, spec: RivetEventStreamFilterSpec): ReadableStream<string>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@alpic80/rivet-core",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"repository": "https://github.com/castortech/rivet",
|
|
5
|
-
"version": "1.24.0-aidon.
|
|
5
|
+
"version": "1.24.0-aidon.4",
|
|
6
6
|
"packageManager": "yarn@3.5.0",
|
|
7
7
|
"main": "dist/cjs/bundle.cjs",
|
|
8
8
|
"module": "dist/esm/index.js",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@google-cloud/vertexai": "^0.1.3",
|
|
49
49
|
"@google/generative-ai": "^0.24.0",
|
|
50
50
|
"@huggingface/inference": "^2.6.4",
|
|
51
|
+
"@ironclad/rivet-core": "npm:@alpic80/rivet-core@1.24.0-aidon.4",
|
|
51
52
|
"assemblyai": "^4.6.0",
|
|
52
53
|
"autoevals": "^0.0.26",
|
|
53
54
|
"cron-parser": "^4.9.0",
|