MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / dumpRequest

Function dumpRequest

source code/services/api/dumpPrompts.ts:92–146  ·  view source on GitHub ↗
(
  body: string,
  ts: string,
  state: DumpState,
  filePath: string,
)

Source from the content-addressed store, hash-verified

90}
91
92function dumpRequest(
93 body: string,
94 ts: string,
95 state: DumpState,
96 filePath: string,
97): void {
98 try {
99 const req = jsonParse(body) as Record<string, unknown>
100 addApiRequestToCache(req)
101
102 if (process.env.USER_TYPE !== 'ant') return
103 const entries: string[] = []
104 const messages = (req.messages ?? []) as Array<{ role?: string }>
105
106 // Write init data (system, tools, metadata) on first request,
107 // and a system_update entry whenever it changes.
108 // Cheap fingerprint first: system+tools don't change between turns,
109 // so skip the 300ms stringify when the shape is unchanged.
110 const fingerprint = initFingerprint(req)
111 if (!state.initialized || fingerprint !== state.lastInitFingerprint) {
112 const { messages: _, ...initData } = req
113 const initDataStr = jsonStringify(initData)
114 const initDataHash = hashString(initDataStr)
115 state.lastInitFingerprint = fingerprint
116 if (!state.initialized) {
117 state.initialized = true
118 state.lastInitDataHash = initDataHash
119 // Reuse initDataStr rather than re-serializing initData inside a wrapper.
120 // timestamp from toISOString() contains no chars needing JSON escaping.
121 entries.push(
122 `{"type":"init","timestamp":"${ts}","data":${initDataStr}}`,
123 )
124 } else if (initDataHash !== state.lastInitDataHash) {
125 state.lastInitDataHash = initDataHash
126 entries.push(
127 `{"type":"system_update","timestamp":"${ts}","data":${initDataStr}}`,
128 )
129 }
130 }
131
132 // Write only new user messages (assistant messages captured in response)
133 for (const msg of messages.slice(state.messageCountSeen)) {
134 if (msg.role === 'user') {
135 entries.push(
136 jsonStringify({ type: 'message', timestamp: ts, data: msg }),
137 )
138 }
139 }
140 state.messageCountSeen = messages.length
141
142 appendToFile(filePath, entries)
143 } catch {
144 // Ignore parsing errors
145 }
146}
147
148export function createDumpPromptsFetch(
149 agentIdOrSessionId: string,

Callers

nothing calls this directly

Calls 6

jsonParseFunction · 0.85
addApiRequestToCacheFunction · 0.85
initFingerprintFunction · 0.85
jsonStringifyFunction · 0.85
appendToFileFunction · 0.85
hashStringFunction · 0.70

Tested by

no test coverage detected