upgrade run ui
This commit is contained in:
1 parent
bb204f2c6c
commit
a10224d21e
6 files changed
+91
-18
No files matched your search
+20
-4
@@ -6,15 +6,18 @@ let unsubscribeRunEvents = null;
|
||||
|
||||
// Event listeners for UI components
|
||||
const listeners = {
|
||||
created: [],
|
||||
runs: [],
|
||||
chats: {},
|
||||
};
|
||||
|
||||
class RunListener {
|
||||
constructor() {
|
||||
constructor() {
|
||||
this.runIds = new Set();
|
||||
this.callbacks = [];
|
||||
this.cancelled = false;
|
||||
this.cancelled = false;
|
||||
|
||||
this.allRuns = false;
|
||||
}
|
||||
|
||||
setIdList(runIds) {
|
||||
@@ -35,7 +38,7 @@ class RunListener {
|
||||
}
|
||||
|
||||
hasRunId(runId) {
|
||||
return this.runIds.has(runId);
|
||||
return this.allRuns || this.runIds.has(runId);
|
||||
}
|
||||
|
||||
emitChange(data) {
|
||||
@@ -56,6 +59,9 @@ function updateRun(event) {
|
||||
if (!run) {
|
||||
run = Object.assign({}, data, {id: runId, events: []});
|
||||
runs.push(run);
|
||||
for (let cb of listeners.created) {
|
||||
cb(run);
|
||||
}
|
||||
} else {
|
||||
console.warn("Created but existing?", run, data);
|
||||
}
|
||||
@@ -71,7 +77,7 @@ function updateRun(event) {
|
||||
}
|
||||
|
||||
if (run) {
|
||||
run.events.push(event);
|
||||
run.events.push({name, runId, data});
|
||||
for (let listener of listeners.runs) {
|
||||
if (listener.hasRunId(runId)) {
|
||||
listener.emitChange(run);
|
||||
@@ -118,6 +124,16 @@ export async function cancelRun(runId) {
|
||||
}
|
||||
|
||||
// Subscribe to runs changes
|
||||
export function onCreated(callback) {
|
||||
listeners.created.push(callback);
|
||||
return () => {
|
||||
const index = listeners.created.indexOf(callback);
|
||||
if (index > -1) {
|
||||
listeners.created.splice(index, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function addRunListener(callback) {
|
||||
const listener = new RunListener();
|
||||
listener.addCallback(callback);
|
||||
|
||||
Reference in new issue
Block a user