11<template >
2- <div class =" tool" :data-tool-name =" toolCall.toolName " :data-tool-state =" toolCall.state"
2+ <div class =" tool" :data-tool-name =" name " :data-tool-state =" toolCall.state"
33 :data-tool-empty-result =" isEmptyResult" :data-tool-error =" !!error" >
44 <div class =" tool-name" >{{ displayName }}</div >
5- <markdown v-if =" toolCall.toolName === 'run_query'" :content =" '```sql\n' + toolCall.args.query + '\n```'" />
5+ <markdown v-if =" name === 'run_query'" :content =" '```sql\n' +
6+ (toolCall.input?.query ||
7+ (toolCall.state === 'output-available' ? '(empty)' : '-- Generating')) +
8+ '\n```'
9+ " />
610 <div v-if =" askingPermission" >
711 {{
8- toolCall.toolName === "run_query"
12+ name === "run_query"
913 ? "Do you want to run this query?"
1014 : "Do you want to proceed?"
1115 }}
2226 </div >
2327 <div class =" tool-error error" v-if =" error" v-text =" error" />
2428 <div class =" tool-result" v-else-if =" data" >
25- <template v-if =" toolCall . toolName === ' get_connection_info' " >
29+ <template v-if =" name === ' get_connection_info' " >
2630 {{ data.connectionType }}
2731 </template >
28- <template v-if =" toolCall . toolName === ' get_tables' " >
32+ <template v-if =" name === ' get_tables' " >
2933 {{ data.length }}
3034 {{ $pluralize("table", data.length) }}
3135 </template >
32- <template v-if =" toolCall . toolName === ' get_columns' " >
36+ <template v-if =" name === ' get_columns' " >
3337 {{ data.length }}
3438 {{ $pluralize("column", data.length) }}
3539 </template >
36- <run-query-result v-else-if =" toolCall.toolName === 'run_query' && data" :data =" data" />
40+ <run-query-result v-else-if =" name === 'run_query' && data" :data =" data" />
3741 </div >
3842 </div >
3943</template >
4044
4145<script lang="ts">
4246import Markdown from " @/components/messages/Markdown.vue" ;
43- import { ToolInvocation } from " ai" ;
47+ import { type ToolUIPart } from " ai" ;
4448import { PropType } from " vue" ;
4549import { safeJSONStringify } from " @/utils" ;
4650import RunQueryResult from " @/components/messages/tool/RunQueryResult.vue" ;
@@ -52,16 +56,20 @@ export default {
5256 props: {
5357 askingPermission: Boolean ,
5458 toolCall: {
55- type: Object as PropType <ToolInvocation >,
59+ type: Object as PropType <ToolUIPart >,
5660 required: true ,
5761 },
62+ args: null ,
5863 },
5964 emits: [" accept" , " reject" ],
6065 computed: {
66+ name() {
67+ return this .toolCall .type .replace (" tool-" , " " );
68+ },
6169 isEmptyResult() {
62- if (this .toolCall .state === " result " ) {
70+ if (this .toolCall .state === " output-available " ) {
6371 return _ .isEmpty (
64- this .toolCall . toolName === " run_query"
72+ this .name === " run_query"
6573 ? this .data .results ?.[0 ]?.rows
6674 : this .data ,
6775 );
@@ -84,26 +92,35 @@ export default {
8492 return " " ;
8593 },
8694 data() {
95+ if (this .toolCall .state !== " output-available" ) {
96+ return null ;
97+ }
98+
8799 try {
88- return JSON .parse (this .toolCall .result );
100+ return JSON .parse (this .toolCall .output );
89101 } catch (e ) {
90102 return null ;
91103 }
92104 },
93105 error() {
94- if (isErrorContent (this .toolCall .result )) {
95- const err = parseErrorContent (this .toolCall .result );
106+ if (
107+ this .toolCall .state === " output-available" &&
108+ isErrorContent (this .toolCall .output )
109+ ) {
110+ const err = parseErrorContent (this .toolCall .output );
96111 return err .message ?? err ;
112+ } else if (this .toolCall .state === " output-error" ) {
113+ return this .toolCall .errorText ;
97114 }
98115 },
99116 displayName() {
100- if (this .toolCall . toolName === " get_columns" ) {
101- if (this .toolCall .args .schema ) {
102- return ` Get Columns (schema: ${this .toolCall .args .schema }, table: ${this .toolCall .args .table }) ` ;
117+ if (this .name === " get_columns" ) {
118+ if (this .toolCall .input ? .schema ) {
119+ return ` Get Columns (schema: ${this .toolCall .input ? .schema }, table: ${this .toolCall .input ? .table || " ... " }) ` ;
103120 }
104- return ` Get Columns (${this .toolCall .args .table }) ` ;
121+ return ` Get Columns (${this .toolCall .input ? .table || " ... " }) ` ;
105122 }
106- return this .toolCall . toolName .split (" _" ).map (_ .capitalize ).join (" " );
123+ return this .name .split (" _" ).map (_ .capitalize ).join (" " );
107124 },
108125 },
109126 methods: {
0 commit comments