cascade-ai 0.12.0 → 0.12.2

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.
package/dist/index.cjs CHANGED
@@ -10605,6 +10605,18 @@ var DashboardSocket = class {
10605
10605
  });
10606
10606
  });
10607
10607
  }
10608
+ emitToSocket(socketId, event, data) {
10609
+ this.io.sockets.sockets.get(socketId)?.emit(event, data);
10610
+ }
10611
+ onCascadeRun(callback) {
10612
+ this.io.on("connection", (socket) => {
10613
+ socket.on("cascade:run", (payload) => {
10614
+ if (typeof payload?.prompt === "string" && payload.prompt.trim()) {
10615
+ callback(payload.prompt.trim(), payload.model ?? "auto", socket.id);
10616
+ }
10617
+ });
10618
+ });
10619
+ }
10608
10620
  close() {
10609
10621
  this.io.close();
10610
10622
  }
@@ -10663,6 +10675,43 @@ var DashboardServer = class {
10663
10675
  }
10664
10676
  }
10665
10677
  });
10678
+ this.socket.onCascadeRun(async (prompt, model, socketId) => {
10679
+ const sessionId = crypto.randomUUID();
10680
+ const cfg = model !== "auto" ? { ...this.config, models: { ...this.config.models, t1: model } } : this.config;
10681
+ const cascade = new Cascade(cfg, this.workspacePath, this.store);
10682
+ this.activeSessions.set(sessionId, cascade);
10683
+ cascade.on("stream:token", (e) => {
10684
+ this.socket.emitToSocket(socketId, "stream:token", { sessionId, tierId: e.tierId, text: e.text });
10685
+ this.socket.broadcast("stream:token", { sessionId, tierId: e.tierId, text: e.text });
10686
+ });
10687
+ cascade.on("tier:status", (e) => {
10688
+ this.socket.emitToSocket(socketId, "tier:status", { sessionId, ...e });
10689
+ this.socket.broadcast("tier:status", { sessionId, ...e });
10690
+ });
10691
+ cascade.on("permission:user-required", (e) => {
10692
+ this.socket.emitToSocket(socketId, "permission:user-required", { sessionId, ...e });
10693
+ });
10694
+ cascade.on("peer:message", (e) => {
10695
+ this.socket.emitPeerMessage(e);
10696
+ });
10697
+ try {
10698
+ const result = await cascade.run({ prompt });
10699
+ this.socket.emitToSocket(socketId, "session:complete", { sessionId, result });
10700
+ this.socket.broadcast("cost:update", {
10701
+ sessionId,
10702
+ totalTokens: result.usage.totalTokens,
10703
+ totalCostUsd: result.usage.estimatedCostUsd
10704
+ });
10705
+ this.throttledBroadcast("workspace");
10706
+ } catch (err) {
10707
+ this.socket.emitToSocket(socketId, "session:error", {
10708
+ sessionId,
10709
+ error: err instanceof Error ? err.message : String(err)
10710
+ });
10711
+ } finally {
10712
+ this.activeSessions.delete(sessionId);
10713
+ }
10714
+ });
10666
10715
  }
10667
10716
  async start() {
10668
10717
  const isLoopback = this.host === "127.0.0.1" || this.host === "::1" || this.host === "localhost";