everydaytok commited on
Commit
110db83
·
verified ·
1 Parent(s): c30dbb0

Update stateManager.js

Browse files
Files changed (1) hide show
  1. stateManager.js +4 -10
stateManager.js CHANGED
@@ -5,9 +5,9 @@ const activeProjects = new Map();
5
  const initializationLocks = new Set();
6
 
7
  // --- REALTIME BUFFERS ---
8
- const streamBuffers = new Map(); // Destructive (For Plugin - Code Execution)
9
- const statusBuffers = new Map(); // Granular Status (For Frontend - "Worker is typing...")
10
- const snapshotBuffers = new Map(); // Non-Destructive (For Frontend - Ghost Text)
11
 
12
  export const initDB = () => {
13
  if (!process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) {
@@ -58,7 +58,6 @@ export const StateManager = {
58
 
59
  addHistory: async (projectId, type, role, text) => {
60
  const newMessage = { role, parts: [{ text }] };
61
-
62
  const project = activeProjects.get(projectId);
63
  if (project) {
64
  const historyKey = type === 'pm' ? 'pmHistory' : 'workerHistory';
@@ -81,10 +80,9 @@ export const StateManager = {
81
 
82
  const latest = chunks?.[0];
83
  const currentPayload = (latest && Array.isArray(latest.payload)) ? latest.payload : [];
84
- const currentSize = currentPayload.length;
85
  const latestIndex = (latest && typeof latest.chunk_index === 'number') ? latest.chunk_index : -1;
86
 
87
- if (latest && currentSize < 20) {
88
  const updatedPayload = [...currentPayload, newMessage];
89
  const { error: updateError } = await supabase.from('message_chunks')
90
  .update({ payload: updatedPayload })
@@ -114,9 +112,6 @@ export const StateManager = {
114
  return statusBuffers.get(projectId) || "Working...";
115
  },
116
 
117
- // --- STREAMING HELPERS ---
118
-
119
- // Use this for WORKER (Goes to Plugin AND Frontend)
120
  appendStream: (projectId, chunk) => {
121
  const currentDestructive = streamBuffers.get(projectId) || "";
122
  streamBuffers.set(projectId, currentDestructive + chunk);
@@ -125,7 +120,6 @@ export const StateManager = {
125
  snapshotBuffers.set(projectId, currentSnapshot + chunk);
126
  },
127
 
128
- // Use this for PM (Goes to Frontend ONLY - User sees thinking, Plugin ignores)
129
  appendSnapshotOnly: (projectId, chunk) => {
130
  const currentSnapshot = snapshotBuffers.get(projectId) || "";
131
  snapshotBuffers.set(projectId, currentSnapshot + chunk);
 
5
  const initializationLocks = new Set();
6
 
7
  // --- REALTIME BUFFERS ---
8
+ const streamBuffers = new Map(); // Destructive (Plugin)
9
+ const statusBuffers = new Map(); // Status (Frontend)
10
+ const snapshotBuffers = new Map(); // Non-Destructive (Frontend)
11
 
12
  export const initDB = () => {
13
  if (!process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) {
 
58
 
59
  addHistory: async (projectId, type, role, text) => {
60
  const newMessage = { role, parts: [{ text }] };
 
61
  const project = activeProjects.get(projectId);
62
  if (project) {
63
  const historyKey = type === 'pm' ? 'pmHistory' : 'workerHistory';
 
80
 
81
  const latest = chunks?.[0];
82
  const currentPayload = (latest && Array.isArray(latest.payload)) ? latest.payload : [];
 
83
  const latestIndex = (latest && typeof latest.chunk_index === 'number') ? latest.chunk_index : -1;
84
 
85
+ if (latest && currentPayload.length < 20) {
86
  const updatedPayload = [...currentPayload, newMessage];
87
  const { error: updateError } = await supabase.from('message_chunks')
88
  .update({ payload: updatedPayload })
 
112
  return statusBuffers.get(projectId) || "Working...";
113
  },
114
 
 
 
 
115
  appendStream: (projectId, chunk) => {
116
  const currentDestructive = streamBuffers.get(projectId) || "";
117
  streamBuffers.set(projectId, currentDestructive + chunk);
 
120
  snapshotBuffers.set(projectId, currentSnapshot + chunk);
121
  },
122
 
 
123
  appendSnapshotOnly: (projectId, chunk) => {
124
  const currentSnapshot = snapshotBuffers.get(projectId) || "";
125
  snapshotBuffers.set(projectId, currentSnapshot + chunk);