MCPcopy Create free account
hub / github.com/Noumena-Network/code / extractActivities

Function extractActivities

src/bridge/sessionRunner.ts:169–262  ·  view source on GitHub ↗
(
  line: string,
  sessionId: string,
  onDebug: (msg: string) => void,
)

Source from the content-addressed store, hash-verified

167}
168
169function extractActivities(
170 line: string,
171 sessionId: string,
172 onDebug: (msg: string) => void,
173): SessionActivity[] {
174 let parsed: unknown
175 try {
176 parsed = jsonParse(line)
177 } catch {
178 return []
179 }
180
181 if (!parsed || typeof parsed !== 'object') {
182 return []
183 }
184
185 const msg = parsed as Record<string, unknown>
186 const activities: SessionActivity[] = []
187 const now = Date.now()
188
189 switch (msg.type) {
190 case 'assistant': {
191 const message = msg.message as Record<string, unknown> | undefined
192 if (!message) break
193 const content = message.content
194 if (!Array.isArray(content)) break
195
196 for (const block of content) {
197 if (!block || typeof block !== 'object') continue
198 const b = block as Record<string, unknown>
199
200 if (b.type === 'tool_use') {
201 const name = (b.name as string) ?? 'Tool'
202 const input = (b.input as Record<string, unknown>) ?? {}
203 const summary = toolSummary(name, input)
204 activities.push({
205 type: 'tool_start',
206 summary,
207 timestamp: now,
208 })
209 onDebug(
210 `[bridge:activity] sessionId=${sessionId} tool_use name=${name} ${inputPreview(input)}`,
211 )
212 } else if (b.type === 'text') {
213 const text = (b.text as string) ?? ''
214 if (text.length > 0) {
215 activities.push({
216 type: 'text',
217 summary: text.slice(0, 80),
218 timestamp: now,
219 })
220 onDebug(
221 `[bridge:activity] sessionId=${sessionId} text "${text.slice(0, 100)}"`,
222 )
223 }
224 }
225 }
226 break

Callers 1

spawnFunction · 0.85

Calls 3

jsonParseFunction · 0.85
toolSummaryFunction · 0.85
inputPreviewFunction · 0.85

Tested by

no test coverage detected