thinkpool-pair 0.7.250 → 0.7.251
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/hermes-event-mapper.mjs +20 -1
- package/package.json +1 -1
package/hermes-event-mapper.mjs
CHANGED
|
@@ -14,6 +14,19 @@ const outputText = (update) => {
|
|
|
14
14
|
return ''
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const diffInput = (content) => {
|
|
18
|
+
const diffs = (Array.isArray(content) ? content : []).filter((part) => part?.type === 'diff')
|
|
19
|
+
if (!diffs.length) return null
|
|
20
|
+
if (diffs.length === 1) return {
|
|
21
|
+
file_path: diffs[0].path || '', path: diffs[0].path || '',
|
|
22
|
+
old_string: diffs[0].oldText || '', new_string: diffs[0].newText || '',
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
file_path: diffs[0].path || '', path: diffs[0].path || '',
|
|
26
|
+
edits: diffs.map((diff) => ({ file_path: diff.path || '', old_string: diff.oldText || '', new_string: diff.newText || '' })),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
export function hermesToolFor(update = {}) {
|
|
18
31
|
const kind = String(update.kind || '').toLowerCase()
|
|
19
32
|
const title = String(update.title || '')
|
|
@@ -22,7 +35,11 @@ export function hermesToolFor(update = {}) {
|
|
|
22
35
|
const shellText = (update.content || []).map(textOf).find((text) => text.trim().startsWith('$ '))
|
|
23
36
|
const location = update.locations?.[0]?.path
|
|
24
37
|
if (kind === 'execute' || terminal || shellText) return { name: 'Bash', input: { ...raw, command: raw.command || shellText?.trim().slice(2) || title } }
|
|
25
|
-
if (kind === 'edit')
|
|
38
|
+
if (kind === 'edit') {
|
|
39
|
+
const diff = diffInput(update.content)
|
|
40
|
+
const name = diff?.edits ? 'MultiEdit' : title.toLowerCase().includes('write') ? 'Write' : 'Edit'
|
|
41
|
+
return { name, input: { ...raw, ...(diff || {}), file_path: diff?.file_path || raw.path || location || '', path: diff?.path || raw.path || location || '' } }
|
|
42
|
+
}
|
|
26
43
|
if (kind === 'read') return { name: 'Read', input: { ...raw, file_path: raw.path || location || '', path: raw.path || location || '' } }
|
|
27
44
|
if (kind === 'search') return { name: 'Grep', input: raw }
|
|
28
45
|
if (kind === 'fetch') return { name: 'WebFetch', input: raw }
|
|
@@ -76,9 +93,11 @@ export class HermesEventMapper {
|
|
|
76
93
|
const merged = { ...prior, ...update }
|
|
77
94
|
this.tools.set(update.toolCallId, merged)
|
|
78
95
|
if (!['completed', 'failed'].includes(update.status)) return
|
|
96
|
+
const completedTool = hermesToolFor(merged)
|
|
79
97
|
this._emit({
|
|
80
98
|
kind: 'tool_result', toolUseId: update.toolCallId,
|
|
81
99
|
content: [{ type: 'text', text: outputText(merged) }],
|
|
100
|
+
toolInput: { ...(prior.input || {}), ...(completedTool.input || {}) },
|
|
82
101
|
isError: update.status === 'failed',
|
|
83
102
|
durationMs: prior.startedAt ? Date.now() - prior.startedAt : undefined,
|
|
84
103
|
parentToolUseId: null,
|