mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat(tooling): preserve native tool titles (#1133)
This commit is contained in:
@@ -2,6 +2,29 @@ import { describe, expect, it } from 'vitest'
|
||||
import { normalizeAgentRecord } from '@/chat/normalizeAgent'
|
||||
|
||||
describe('normalizeAgentRecord — agentTimestamp exposure', () => {
|
||||
it('preserves normalized native tool presentation metadata', () => {
|
||||
const normalized = normalizeAgentRecord('msg-native', null, 1, {
|
||||
type: 'codex',
|
||||
data: {
|
||||
type: 'tool-call',
|
||||
callId: 'call-native',
|
||||
name: 'Bash',
|
||||
input: { command: 'bun test' },
|
||||
nativeTitle: 'Run project tests',
|
||||
nativeKind: 'execute'
|
||||
}
|
||||
})
|
||||
|
||||
expect(normalized).toMatchObject({
|
||||
role: 'agent',
|
||||
content: [{
|
||||
type: 'tool-call',
|
||||
nativeTitle: 'Run project tests',
|
||||
nativeKind: 'execute'
|
||||
}]
|
||||
})
|
||||
})
|
||||
|
||||
it('parses data.timestamp into agentTimestamp for an assistant tool_use record', () => {
|
||||
const normalized = normalizeAgentRecord('msg-1', null, 1_783_953_478_235, {
|
||||
type: 'output',
|
||||
|
||||
@@ -738,7 +738,9 @@ export function normalizeAgentRecord(
|
||||
id: data.callId,
|
||||
name: asString(data.name) ?? 'unknown',
|
||||
input: data.input,
|
||||
description: null,
|
||||
description: asString(data.description),
|
||||
nativeTitle: asString(data.nativeTitle ?? data.title),
|
||||
nativeKind: asString(data.nativeKind ?? data.kind),
|
||||
uuid,
|
||||
parentUUID: null
|
||||
}],
|
||||
|
||||
@@ -880,6 +880,8 @@ export function reduceTimeline(
|
||||
name: c.name,
|
||||
input: c.input,
|
||||
description: c.description,
|
||||
nativeTitle: c.nativeTitle,
|
||||
nativeKind: c.nativeKind,
|
||||
permission,
|
||||
agentTimestamp: msg.agentTimestamp
|
||||
})
|
||||
|
||||
@@ -65,6 +65,8 @@ export function ensureToolBlock(
|
||||
name: string
|
||||
input: unknown
|
||||
description: string | null
|
||||
nativeTitle?: string | null
|
||||
nativeKind?: string | null
|
||||
permission?: ToolPermission
|
||||
/** Claude entry execution-machine timestamp for the tool_use, if known (see `ChatToolCall.execStartedAt`). */
|
||||
agentTimestamp?: number | null
|
||||
@@ -99,6 +101,12 @@ export function ensureToolBlock(
|
||||
if (seed.description !== null) {
|
||||
existing.tool = { ...existing.tool, description: seed.description }
|
||||
}
|
||||
if (seed.nativeTitle != null) {
|
||||
existing.tool = { ...existing.tool, nativeTitle: seed.nativeTitle }
|
||||
}
|
||||
if (seed.nativeKind != null) {
|
||||
existing.tool = { ...existing.tool, nativeKind: seed.nativeKind }
|
||||
}
|
||||
// The first call (tool_use) records when the tool was invoked. The
|
||||
// second call (tool_result) carries the result message's invokedAt,
|
||||
// which is when the result was processed — not when the tool was
|
||||
@@ -139,6 +147,8 @@ export function ensureToolBlock(
|
||||
execStartedAt: initialState === 'running' ? (seed.agentTimestamp ?? null) : null,
|
||||
execCompletedAt: null,
|
||||
description: seed.description,
|
||||
nativeTitle: seed.nativeTitle ?? null,
|
||||
nativeKind: seed.nativeKind ?? null,
|
||||
permission: seed.permission
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ export type ToolUse = {
|
||||
name: string
|
||||
input: unknown
|
||||
description: string | null
|
||||
nativeTitle?: string | null
|
||||
nativeKind?: string | null
|
||||
uuid: string
|
||||
parentUUID: string | null
|
||||
}
|
||||
@@ -175,6 +177,8 @@ export type ChatToolCall = {
|
||||
execStartedAt: number | null
|
||||
execCompletedAt: number | null
|
||||
description: string | null
|
||||
nativeTitle?: string | null
|
||||
nativeKind?: string | null
|
||||
result?: unknown
|
||||
permission?: ToolPermission
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user