MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / withEvent

Function withEvent

graph-ui/src/agents/agent-store.ts:134–195  ·  view source on GitHub ↗
(state: AgentsState, event: AgentEvent)

Source from the content-addressed store, hash-verified

132
133/** Ein Ereignis in den Zustand aufnehmen. Rein, damit ein Test ihn nachbauen kann. */
134export function withEvent(state: AgentsState, event: AgentEvent): AgentsState {
135 // A retry must not increment counts or append another timeline row. Lower
136 // sequence numbers are still accepted when they arrive late.
137 if (state.actors.some((actor) => actor.events.some((seenEvent) =>
138 seenEvent.run === event.run && seenEvent.seq === event.seq))) return state;
139 const id = event.agent;
140 const existing = state.actors.find((actor) => actor.id === id);
141 const seen = new Map(state.seen);
142 const previous = seen.get(event.run);
143 if (previous === undefined || event.seq > previous) {
144 seen.set(event.run, event.seq);
145 }
146
147 if (existing === undefined) {
148 const actor: ActorState = {
149 id,
150 name: id,
151 you: false,
152 runs: [{ run: event.run, joinedAt: event.seq, lastSeq: event.seq, missed: 0 }],
153 events: [event],
154 last: event,
155 kind: workKindOf(event.tool, event.detail),
156 firstTs: event.ts,
157 lastTs: event.ts,
158 count: 1,
159 missed: 0,
160 };
161 return {
162 actors: [...state.actors, actor],
163 events: state.events + 1,
164 missed: state.missed,
165 seen,
166 unreadable: state.unreadable,
167 };
168 }
169
170 const { runs, missed } = withRun(existing.runs, event);
171 const events = [...existing.events, event].slice(-ACTOR_EVENT_CAP);
172 // Das letzte Ereignis ist das mit der spaetesten Zeit und nicht das zuletzt
173 // eingetroffene: bei einer Wiederaufnahme koennen aeltere Ereignisse
174 // nachkommen, und ein Koerper, der dabei zurueckspringt, waere eine
175 // Bewegung, die es nicht gab.
176 const last = event.ts >= existing.lastTs ? event : existing.last;
177 const updated: ActorState = {
178 ...existing,
179 runs,
180 events,
181 last,
182 kind: workKindOf(last.tool, last.detail),
183 firstTs: Math.min(existing.firstTs, event.ts),
184 lastTs: Math.max(existing.lastTs, event.ts),
185 count: existing.count + 1,
186 missed: existing.missed + missed,
187 };
188 return {
189 actors: state.actors.map((actor) => (actor.id === id ? updated : actor)),
190 events: state.events + 1,
191 missed: state.missed + missed,

Callers 7

foldFunction · 0.90
buildFunction · 0.90
agent-view.test.tsFile · 0.90
useAgentStreamFunction · 0.90
connectFunction · 0.90
withYouEventFunction · 0.85

Calls 3

workKindOfFunction · 0.90
withRunFunction · 0.85
getMethod · 0.65

Tested by 2

foldFunction · 0.72
buildFunction · 0.72