Skip to content

Commit be28778

Browse files
authored
fix(inspect): show agent invoke parsing errors (#373)
1 parent 5f6d5be commit be28778

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

plugins/inspect/app/components/AgentView.vue

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import type { AgentManifest, InvokeResult } from '../connect'
33
import ActionButton from '@antfu/design/components/Action/ActionButton.vue'
4+
import FeedbackTip from '@antfu/design/components/Feedback/FeedbackTip.vue'
45
import { toAgentToolName } from 'devframe/utils/agent-tool-name'
56
import { reactive, ref } from 'vue'
67
import JsonView from './JsonView.vue'
@@ -19,6 +20,7 @@ const emit = defineEmits<{
1920
2021
const expanded = ref<string | null>(null)
2122
const argsInput = reactive<Record<string, string>>({})
23+
const invokeErrors = reactive<Record<string, string>>({})
2224
2325
function toggle(id: string): void {
2426
expanded.value = expanded.value === id ? null : id
@@ -34,12 +36,21 @@ function invokeTool(id: string) {
3436
parsed = raw
3537
}
3638
catch (err) {
37-
// Emitting error would be cleaner, for now we will throw to stop execution
38-
throw new Error(`Invalid JSON args: ${(err as Error).message}`)
39+
invokeErrors[id] = `Invalid JSON arguments: ${(err as Error).message}`
40+
return
3941
}
42+
delete invokeErrors[id]
4043
emit('invoke', id, parsed)
4144
}
4245
46+
function clearInvokeError(id: string): void {
47+
delete invokeErrors[id]
48+
}
49+
50+
function invokeErrorId(id: string): string {
51+
return `agent-invoke-error-${toAgentToolName(id)}`
52+
}
53+
4354
function readResource(id: string) {
4455
emit('read', id)
4556
}
@@ -100,7 +111,25 @@ function readResource(id: string) {
100111
<div class="label">
101112
Invoke (MCP format)
102113
</div>
103-
<textarea v-model="argsInput[tool.id]" class="args" spellcheck="false" placeholder="{}" />
114+
<textarea
115+
v-model="argsInput[tool.id]"
116+
class="args"
117+
spellcheck="false"
118+
placeholder="{}"
119+
:aria-invalid="!!invokeErrors[tool.id]"
120+
:aria-describedby="invokeErrors[tool.id] ? invokeErrorId(tool.id) : undefined"
121+
@input="clearInvokeError(tool.id)"
122+
/>
123+
<FeedbackTip
124+
v-if="invokeErrors[tool.id]"
125+
:id="invokeErrorId(tool.id)"
126+
class="mt-2"
127+
type="error"
128+
icon="i-ph-warning-circle-duotone"
129+
role="alert"
130+
>
131+
{{ invokeErrors[tool.id] }}
132+
</FeedbackTip>
104133
<div style="margin-top: 8px; display: flex; gap: 8px; align-items: center;">
105134
<ActionButton
106135
variant="primary"

0 commit comments

Comments
 (0)