llms-py 2.0.20__py3-none-any.whl → 3.0.10__py3-none-any.whl
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.
- llms/__init__.py +3 -1
- llms/db.py +359 -0
- llms/{ui/Analytics.mjs → extensions/analytics/ui/index.mjs} +254 -327
- llms/extensions/app/README.md +20 -0
- llms/extensions/app/__init__.py +589 -0
- llms/extensions/app/db.py +536 -0
- llms/{ui → extensions/app/ui}/Recents.mjs +99 -73
- llms/{ui/Sidebar.mjs → extensions/app/ui/index.mjs} +139 -68
- llms/extensions/app/ui/threadStore.mjs +433 -0
- llms/extensions/core_tools/CALCULATOR.md +32 -0
- llms/extensions/core_tools/__init__.py +637 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/closebrackets.js +201 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/closetag.js +185 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/continuelist.js +101 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/matchbrackets.js +160 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/matchtags.js +66 -0
- llms/extensions/core_tools/ui/codemirror/addon/edit/trailingspace.js +27 -0
- llms/extensions/core_tools/ui/codemirror/addon/selection/active-line.js +72 -0
- llms/extensions/core_tools/ui/codemirror/addon/selection/mark-selection.js +119 -0
- llms/extensions/core_tools/ui/codemirror/addon/selection/selection-pointer.js +98 -0
- llms/extensions/core_tools/ui/codemirror/codemirror.css +344 -0
- llms/extensions/core_tools/ui/codemirror/codemirror.js +9884 -0
- llms/extensions/core_tools/ui/codemirror/doc/docs.css +225 -0
- llms/extensions/core_tools/ui/codemirror/doc/source_sans.woff +0 -0
- llms/extensions/core_tools/ui/codemirror/mode/clike/clike.js +942 -0
- llms/extensions/core_tools/ui/codemirror/mode/javascript/index.html +118 -0
- llms/extensions/core_tools/ui/codemirror/mode/javascript/javascript.js +962 -0
- llms/extensions/core_tools/ui/codemirror/mode/javascript/typescript.html +62 -0
- llms/extensions/core_tools/ui/codemirror/mode/python/python.js +402 -0
- llms/extensions/core_tools/ui/codemirror/theme/dracula.css +40 -0
- llms/extensions/core_tools/ui/codemirror/theme/mocha.css +135 -0
- llms/extensions/core_tools/ui/index.mjs +650 -0
- llms/extensions/gallery/README.md +61 -0
- llms/extensions/gallery/__init__.py +63 -0
- llms/extensions/gallery/db.py +243 -0
- llms/extensions/gallery/ui/index.mjs +482 -0
- llms/extensions/katex/README.md +39 -0
- llms/extensions/katex/__init__.py +6 -0
- llms/extensions/katex/ui/README.md +125 -0
- llms/extensions/katex/ui/contrib/auto-render.js +338 -0
- llms/extensions/katex/ui/contrib/auto-render.min.js +1 -0
- llms/extensions/katex/ui/contrib/auto-render.mjs +244 -0
- llms/extensions/katex/ui/contrib/copy-tex.js +127 -0
- llms/extensions/katex/ui/contrib/copy-tex.min.js +1 -0
- llms/extensions/katex/ui/contrib/copy-tex.mjs +105 -0
- llms/extensions/katex/ui/contrib/mathtex-script-type.js +109 -0
- llms/extensions/katex/ui/contrib/mathtex-script-type.min.js +1 -0
- llms/extensions/katex/ui/contrib/mathtex-script-type.mjs +24 -0
- llms/extensions/katex/ui/contrib/mhchem.js +3213 -0
- llms/extensions/katex/ui/contrib/mhchem.min.js +1 -0
- llms/extensions/katex/ui/contrib/mhchem.mjs +3109 -0
- llms/extensions/katex/ui/contrib/render-a11y-string.js +887 -0
- llms/extensions/katex/ui/contrib/render-a11y-string.min.js +1 -0
- llms/extensions/katex/ui/contrib/render-a11y-string.mjs +800 -0
- llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- llms/extensions/katex/ui/index.mjs +92 -0
- llms/extensions/katex/ui/katex-swap.css +1230 -0
- llms/extensions/katex/ui/katex-swap.min.css +1 -0
- llms/extensions/katex/ui/katex.css +1230 -0
- llms/extensions/katex/ui/katex.js +19080 -0
- llms/extensions/katex/ui/katex.min.css +1 -0
- llms/extensions/katex/ui/katex.min.js +1 -0
- llms/extensions/katex/ui/katex.min.mjs +1 -0
- llms/extensions/katex/ui/katex.mjs +18547 -0
- llms/extensions/providers/__init__.py +22 -0
- llms/extensions/providers/anthropic.py +233 -0
- llms/extensions/providers/cerebras.py +37 -0
- llms/extensions/providers/chutes.py +153 -0
- llms/extensions/providers/google.py +481 -0
- llms/extensions/providers/nvidia.py +103 -0
- llms/extensions/providers/openai.py +154 -0
- llms/extensions/providers/openrouter.py +74 -0
- llms/extensions/providers/zai.py +182 -0
- llms/extensions/system_prompts/README.md +22 -0
- llms/extensions/system_prompts/__init__.py +45 -0
- llms/extensions/system_prompts/ui/index.mjs +280 -0
- llms/extensions/system_prompts/ui/prompts.json +1067 -0
- llms/extensions/tools/__init__.py +144 -0
- llms/extensions/tools/ui/index.mjs +706 -0
- llms/index.html +36 -62
- llms/llms.json +180 -879
- llms/main.py +3640 -899
- llms/providers-extra.json +394 -0
- llms/providers.json +1 -0
- llms/ui/App.mjs +176 -8
- llms/ui/ai.mjs +156 -20
- llms/ui/app.css +3161 -244
- llms/ui/ctx.mjs +412 -0
- llms/ui/index.mjs +131 -0
- llms/ui/lib/chart.js +14 -0
- llms/ui/lib/charts.mjs +16 -0
- llms/ui/lib/color.js +14 -0
- llms/ui/lib/highlight.min.mjs +1243 -0
- llms/ui/lib/idb.min.mjs +8 -0
- llms/ui/lib/marked.min.mjs +8 -0
- llms/ui/lib/servicestack-client.mjs +1 -0
- llms/ui/lib/servicestack-vue.mjs +37 -0
- llms/ui/lib/vue-router.min.mjs +6 -0
- llms/ui/lib/vue.min.mjs +13 -0
- llms/ui/lib/vue.mjs +18530 -0
- llms/ui/markdown.mjs +25 -14
- llms/ui/modules/chat/ChatBody.mjs +976 -0
- llms/ui/{SettingsDialog.mjs → modules/chat/SettingsDialog.mjs} +74 -74
- llms/ui/modules/chat/index.mjs +991 -0
- llms/ui/modules/icons.mjs +46 -0
- llms/ui/modules/layout.mjs +271 -0
- llms/ui/modules/model-selector.mjs +811 -0
- llms/ui/tailwind.input.css +550 -78
- llms/ui/typography.css +54 -36
- llms/ui/utils.mjs +197 -92
- llms_py-3.0.10.dist-info/METADATA +49 -0
- llms_py-3.0.10.dist-info/RECORD +177 -0
- {llms_py-2.0.20.dist-info → llms_py-3.0.10.dist-info}/licenses/LICENSE +1 -2
- llms/ui/Avatar.mjs +0 -28
- llms/ui/Brand.mjs +0 -34
- llms/ui/ChatPrompt.mjs +0 -443
- llms/ui/Main.mjs +0 -740
- llms/ui/ModelSelector.mjs +0 -60
- llms/ui/ProviderIcon.mjs +0 -29
- llms/ui/ProviderStatus.mjs +0 -105
- llms/ui/SignIn.mjs +0 -64
- llms/ui/SystemPromptEditor.mjs +0 -31
- llms/ui/SystemPromptSelector.mjs +0 -36
- llms/ui/Welcome.mjs +0 -8
- llms/ui/threadStore.mjs +0 -524
- llms/ui.json +0 -1069
- llms_py-2.0.20.dist-info/METADATA +0 -931
- llms_py-2.0.20.dist-info/RECORD +0 -36
- {llms_py-2.0.20.dist-info → llms_py-3.0.10.dist-info}/WHEEL +0 -0
- {llms_py-2.0.20.dist-info → llms_py-3.0.10.dist-info}/entry_points.txt +0 -0
- {llms_py-2.0.20.dist-info → llms_py-3.0.10.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import { inject, computed, ref, onMounted } from "vue"
|
|
2
|
+
|
|
3
|
+
let ext
|
|
4
|
+
|
|
5
|
+
const ToolResult = {
|
|
6
|
+
template: `
|
|
7
|
+
<div>
|
|
8
|
+
<div class="flex items-center gap-2 text-[10px] uppercase tracking-wider font-medium select-none">
|
|
9
|
+
<span @click="ext.setPrefs({ toolFormat: 'text' })"
|
|
10
|
+
class="cursor-pointer transition-colors"
|
|
11
|
+
:class="ext.prefs.toolFormat !== 'preview' ? 'text-gray-600 dark:text-gray-300' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'">
|
|
12
|
+
text
|
|
13
|
+
</span>
|
|
14
|
+
<span class="text-gray-300 dark:text-gray-700">|</span>
|
|
15
|
+
<span @click="ext.setPrefs({ toolFormat: 'preview' })"
|
|
16
|
+
class="cursor-pointer transition-colors"
|
|
17
|
+
:class="ext.prefs.toolFormat == 'preview' ? 'text-gray-600 dark:text-gray-300' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'">
|
|
18
|
+
preview
|
|
19
|
+
</span>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="not-prose px-3 py-2">
|
|
22
|
+
<pre v-if="ext.prefs.toolFormat !== 'preview'" class="tool-output">{{ origResult }}</pre>
|
|
23
|
+
<div v-else>
|
|
24
|
+
<ViewTypes v-if="Array.isArray(result)" :results="result" />
|
|
25
|
+
<ViewType v-else :result="result" />
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
`,
|
|
30
|
+
props: {
|
|
31
|
+
result: {
|
|
32
|
+
required: true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
setup(props) {
|
|
36
|
+
|
|
37
|
+
const origResult = computed(() => {
|
|
38
|
+
let ret = props.result
|
|
39
|
+
if (Array.isArray(props.result) && props.result.length == 1) {
|
|
40
|
+
ret = props.result[0]
|
|
41
|
+
}
|
|
42
|
+
if (ret.type) {
|
|
43
|
+
if (ret.type === "text") {
|
|
44
|
+
return ret.text
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return props.result
|
|
48
|
+
})
|
|
49
|
+
const displayResult = computed(() => {
|
|
50
|
+
try {
|
|
51
|
+
let result = typeof props.result == 'string'
|
|
52
|
+
? JSON.parse(props.result)
|
|
53
|
+
: props.result
|
|
54
|
+
if (Array.isArray(result) && result.length == 1) {
|
|
55
|
+
result = result[0]
|
|
56
|
+
}
|
|
57
|
+
if (result.type) {
|
|
58
|
+
if (result.type === "text") {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(result.text)
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return result.text
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return props.result
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
return {
|
|
72
|
+
ext,
|
|
73
|
+
origResult,
|
|
74
|
+
displayResult,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const Tools = {
|
|
80
|
+
components: {
|
|
81
|
+
ToolResult
|
|
82
|
+
},
|
|
83
|
+
template: `
|
|
84
|
+
<div class="p-4 md:p-6 max-w-7xl mx-auto w-full relative">
|
|
85
|
+
<div v-if="Object.keys($ctx.tools.toolPageHeaders).length">
|
|
86
|
+
<div v-for="(component, key) in $ctx.tools.toolPageHeaders" :key="key">
|
|
87
|
+
<component :is="component" />
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div ref="refTop" class="mb-6 flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
91
|
+
<div>
|
|
92
|
+
<h1 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Tools</h1>
|
|
93
|
+
<p class="text-gray-600 dark:text-gray-400 mt-1">
|
|
94
|
+
{{ filteredTools.length }} tools available
|
|
95
|
+
</p>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div v-if="groups.length > 0" class="flex flex-wrap items-center gap-2">
|
|
99
|
+
<button @click="ext.setPrefs({ selectedGroup: 'All' })"
|
|
100
|
+
class="px-2.5 py-1 rounded-full text-xs font-medium border transition-colors select-none"
|
|
101
|
+
:class="ext.prefs.selectedGroup === 'All'
|
|
102
|
+
? 'bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300 border-green-300 dark:border-green-800'
|
|
103
|
+
: 'cursor-pointer bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
104
|
+
All
|
|
105
|
+
</button>
|
|
106
|
+
|
|
107
|
+
<div class="border-l h-4 mx-1 border-gray-300 dark:border-gray-600"></div>
|
|
108
|
+
|
|
109
|
+
<button v-for="group in groups" :key="group"
|
|
110
|
+
@click="ext.setPrefs({ selectedGroup: group})"
|
|
111
|
+
class="px-2.5 py-1 rounded-full text-xs font-medium border transition-colors select-none"
|
|
112
|
+
:class="ext.prefs.selectedGroup === group
|
|
113
|
+
? 'bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300 border-blue-200 dark:border-blue-800'
|
|
114
|
+
: 'cursor-pointer bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
115
|
+
{{ group }}
|
|
116
|
+
</button>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- Execution Form Panel -->
|
|
121
|
+
<div v-if="executingTool" class="mb-8 bg-white dark:bg-gray-800 rounded-lg border border-blue-200 dark:border-blue-800 shadow-sm overflow-hidden animate-in fade-in slide-in-from-top-4 duration-200">
|
|
122
|
+
<div class="bg-blue-50 dark:bg-blue-900/30 px-4 py-3 border-b border-blue-100 dark:border-blue-800 flex justify-between items-center">
|
|
123
|
+
<div class="flex items-center gap-2">
|
|
124
|
+
<h3 class="font-bold text-gray-900 dark:text-gray-100">Execute: <span class="font-mono text-blue-600 dark:text-blue-400">{{ executingTool.function.name }}</span></h3>
|
|
125
|
+
</div>
|
|
126
|
+
<button @click="closeExec" type="button" class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
|
|
127
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
|
128
|
+
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
129
|
+
</svg>
|
|
130
|
+
</button>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<div class="p-4 md:p-6">
|
|
134
|
+
<form ref="refForm" @submit.prevent="execTool" class="space-y-4">
|
|
135
|
+
<div v-if="Object.keys(executingTool.function.parameters?.properties || {}).length > 0" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
136
|
+
<div v-for="(prop, name) in executingTool.function.parameters.properties" :key="name">
|
|
137
|
+
<label :for="'input-' + name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
|
138
|
+
{{ name }}
|
|
139
|
+
<span v-if="executingTool.function.parameters.required?.includes(name)" class="text-red-500">*</span>
|
|
140
|
+
</label>
|
|
141
|
+
|
|
142
|
+
<div v-if="prop.enum">
|
|
143
|
+
<select v-model="execForm[name]" :id="'input-' + name" class="block w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
|
|
144
|
+
<option :value="undefined" disabled>Select...</option>
|
|
145
|
+
<option v-for="opt in prop.enum" :key="opt" :value="opt">{{ opt }}</option>
|
|
146
|
+
</select>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<div v-else-if="prop.type === 'boolean'">
|
|
150
|
+
<select v-model="execForm[name]" :id="'input-' + name" class="block w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
|
|
151
|
+
<option :value="false">False</option>
|
|
152
|
+
<option :value="true">True</option>
|
|
153
|
+
</select>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div v-else>
|
|
157
|
+
<input :type="prop.type === 'integer' || prop.type === 'number' ? 'number' : 'text'"
|
|
158
|
+
v-model="execForm[name]"
|
|
159
|
+
:id="'input-' + name"
|
|
160
|
+
:placeholder="prop.description"
|
|
161
|
+
:step="prop.type === 'integer' ? 1 : 0.01"
|
|
162
|
+
class="block w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
|
|
163
|
+
</div>
|
|
164
|
+
<p v-if="prop.description" class="mt-1 text-xs text-gray-500 dark:text-gray-400">{{ prop.description }}</p>
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
<div v-else class="text-gray-500 dark:text-gray-400 italic">
|
|
168
|
+
No parameters required.
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div class="flex items-center gap-3 pt-4 border-t border-gray-100 dark:border-gray-700">
|
|
172
|
+
<button type="submit" :disabled="loading"
|
|
173
|
+
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed">
|
|
174
|
+
<svg v-if="loading" class="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
175
|
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
176
|
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
177
|
+
</svg>
|
|
178
|
+
{{ loading ? 'Executing...' : 'Run Tool' }}
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
</form>
|
|
182
|
+
|
|
183
|
+
<div v-if="execResult !== null || execError" class="mt-6">
|
|
184
|
+
<h4 class="text-sm font-medium text-gray-900 dark:text-gray-100 mb-2">Response:</h4>
|
|
185
|
+
<div v-if="execError" class="p-4 rounded-md bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-300 font-mono text-sm whitespace-pre-wrap">
|
|
186
|
+
{{ execError }}
|
|
187
|
+
</div>
|
|
188
|
+
<ToolResult v-else :result="execResult" />
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
|
194
|
+
<div v-for="tool in filteredTools" :key="tool.function.name"
|
|
195
|
+
class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden flex flex-col">
|
|
196
|
+
|
|
197
|
+
<div class="p-4 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 flex justify-between items-center">
|
|
198
|
+
<div class="font-bold text-lg text-gray-900 dark:text-gray-100 font-mono break-all mr-2">
|
|
199
|
+
{{ tool.function.name }}
|
|
200
|
+
</div>
|
|
201
|
+
<button @click="startExec(tool)" type="button" title="Execute Tool" class="text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 border-none">
|
|
202
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="size-6" viewBox="0 0 20 20" fill="currentColor">
|
|
203
|
+
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd" />
|
|
204
|
+
</svg>
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
<div class="tool-description p-4 flex-1 flex flex-col">
|
|
209
|
+
<div v-if="tool.function.description" class="text-sm text-gray-600 dark:text-gray-300 mb-4 flex-1 flex flex-col">
|
|
210
|
+
<div v-if="tool.function.description.length < 350">
|
|
211
|
+
<div v-html="$fmt.markdown(tool.function.description)"></div>
|
|
212
|
+
</div>
|
|
213
|
+
<div v-else>
|
|
214
|
+
<div class="relative transition-all duration-300 ease-in-out"
|
|
215
|
+
:class="{'max-h-[200px] overflow-hidden': !isExpanded(tool.function.name)}">
|
|
216
|
+
<div v-html="$fmt.markdown(tool.function.description)" :title="tool.function.description"></div>
|
|
217
|
+
|
|
218
|
+
<!-- Fade overlay when collapsed -->
|
|
219
|
+
<div v-if="!isExpanded(tool.function.name)"
|
|
220
|
+
class="absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-white dark:from-gray-800 to-transparent pointer-events-none">
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<button @click="toggleDescription(tool.function.name)"
|
|
225
|
+
type="button"
|
|
226
|
+
class="mt-1 text-xs font-medium text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 focus:outline-none self-start">
|
|
227
|
+
{{ isExpanded(tool.function.name) ? 'Show Less' : 'Show More' }}
|
|
228
|
+
</button>
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
<p v-else class="text-sm text-gray-400 italic mb-4 flex-1">
|
|
232
|
+
No description provided
|
|
233
|
+
</p>
|
|
234
|
+
|
|
235
|
+
<div v-if="tool.function.parameters?.properties && Object.keys(tool.function.parameters.properties).length > 0">
|
|
236
|
+
<div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">Parameters</div>
|
|
237
|
+
<div class="space-y-3">
|
|
238
|
+
<div v-for="(prop, name) in tool.function.parameters.properties" :key="name" class="text-sm bg-gray-50 dark:bg-gray-700/30 rounded p-2">
|
|
239
|
+
<div class="flex flex-wrap items-baseline gap-2 mb-1">
|
|
240
|
+
<span class="font-mono font-medium text-blue-600 dark:text-blue-400">{{ name }}</span>
|
|
241
|
+
<span class="text-gray-500 text-xs">({{ prop.type }})</span>
|
|
242
|
+
<span v-if="tool.function.parameters.required?.includes(name)"
|
|
243
|
+
class="px-1.5 py-0.5 text-[10px] rounded bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-400 font-medium">
|
|
244
|
+
REQUIRED
|
|
245
|
+
</span>
|
|
246
|
+
</div>
|
|
247
|
+
<div v-if="prop.description" class="text-gray-600 dark:text-gray-400 text-xs">
|
|
248
|
+
{{ prop.description }}
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
<div v-else class="text-sm text-gray-400 italic border-t border-gray-100 dark:border-gray-700 pt-2 mt-auto">
|
|
254
|
+
No parameters
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
`,
|
|
261
|
+
setup() {
|
|
262
|
+
const ctx = inject('ctx')
|
|
263
|
+
|
|
264
|
+
// Execution State
|
|
265
|
+
const executingTool = ref(null)
|
|
266
|
+
const execForm = ref({})
|
|
267
|
+
const execResult = ref(null)
|
|
268
|
+
const execError = ref(null)
|
|
269
|
+
const loading = ref(false)
|
|
270
|
+
const refForm = ref()
|
|
271
|
+
const refTop = ref()
|
|
272
|
+
|
|
273
|
+
// UI State
|
|
274
|
+
const expandedDescriptions = ref({})
|
|
275
|
+
|
|
276
|
+
const groups = computed(() => Object.keys(ctx.state.tool.groups || {}))
|
|
277
|
+
|
|
278
|
+
const filteredTools = computed(() => {
|
|
279
|
+
const allTools = ctx.state.tool.definitions.filter(x => x.function)
|
|
280
|
+
if (ext.prefs.selectedGroup === 'All') return allTools
|
|
281
|
+
|
|
282
|
+
const groupTools = ctx.state.tool.groups[ext.prefs.selectedGroup] || []
|
|
283
|
+
return allTools.filter(t => groupTools.includes(t.function.name))
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
function startExec(tool) {
|
|
287
|
+
executingTool.value = tool
|
|
288
|
+
execForm.value = {}
|
|
289
|
+
execResult.value = null
|
|
290
|
+
execError.value = null
|
|
291
|
+
|
|
292
|
+
// Initialize defaults if any
|
|
293
|
+
if (tool.function.parameters?.properties) {
|
|
294
|
+
Object.entries(tool.function.parameters.properties).forEach(([key, prop]) => {
|
|
295
|
+
if (prop.default !== undefined) {
|
|
296
|
+
execForm.value[key] = prop.default
|
|
297
|
+
}
|
|
298
|
+
// Initialize booleans to false if likely
|
|
299
|
+
if (prop.type === 'boolean' && prop.default === undefined) {
|
|
300
|
+
// Optional: default to false? or maybe undefined is better to force user choice or let server handle it?
|
|
301
|
+
// Let's leave it undefined unless explicitly set
|
|
302
|
+
execForm.value[key] = false
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
// Scroll to top
|
|
307
|
+
// window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
308
|
+
refForm.value?.scrollIntoView({ behavior: 'smooth' })
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function closeExec() {
|
|
312
|
+
executingTool.value = null
|
|
313
|
+
execForm.value = {}
|
|
314
|
+
execResult.value = null
|
|
315
|
+
execError.value = null
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function execTool() {
|
|
319
|
+
if (!executingTool.value) return
|
|
320
|
+
|
|
321
|
+
loading.value = true
|
|
322
|
+
execResult.value = null
|
|
323
|
+
execError.value = null
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
const ext = ctx.scope('tools')
|
|
327
|
+
// Filter out undefined values to avoid sending empty params that might confuse backend validation
|
|
328
|
+
// Or maybe send them as null? existing backend `tool_prop_value` handles things.
|
|
329
|
+
const payload = { ...execForm.value }
|
|
330
|
+
|
|
331
|
+
// Ensure numbers are numbers
|
|
332
|
+
if (executingTool.value.function.parameters?.properties) {
|
|
333
|
+
Object.entries(executingTool.value.function.parameters.properties).forEach(([key, prop]) => {
|
|
334
|
+
if ((prop.type === 'integer' || prop.type === 'number') && payload[key] !== '') {
|
|
335
|
+
payload[key] = Number(payload[key])
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const res = await ext.postJson('/exec/' + executingTool.value.function.name, payload)
|
|
341
|
+
if (res.error) {
|
|
342
|
+
execError.value = res.error.message
|
|
343
|
+
} else {
|
|
344
|
+
execResult.value = res.response
|
|
345
|
+
}
|
|
346
|
+
} catch (e) {
|
|
347
|
+
execError.value = e.message || 'Unknown error occurred'
|
|
348
|
+
} finally {
|
|
349
|
+
loading.value = false
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function toggleDescription(name) {
|
|
354
|
+
expandedDescriptions.value[name] = !expandedDescriptions.value[name]
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function isExpanded(name) {
|
|
358
|
+
return !!expandedDescriptions.value[name]
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
onMounted(() => {
|
|
362
|
+
if (!ext.prefs.selectedGroup) {
|
|
363
|
+
ext.setPrefs({ selectedGroup: 'All' })
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
return {
|
|
368
|
+
ext,
|
|
369
|
+
refForm,
|
|
370
|
+
refTop,
|
|
371
|
+
groups,
|
|
372
|
+
filteredTools,
|
|
373
|
+
// Exec
|
|
374
|
+
executingTool,
|
|
375
|
+
execForm,
|
|
376
|
+
execResult,
|
|
377
|
+
execError,
|
|
378
|
+
loading,
|
|
379
|
+
startExec,
|
|
380
|
+
closeExec,
|
|
381
|
+
execTool,
|
|
382
|
+
// UI
|
|
383
|
+
toggleDescription,
|
|
384
|
+
isExpanded
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const ToolSelector = {
|
|
390
|
+
template: `
|
|
391
|
+
<div class="px-4 py-4 bg-gray-50 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 max-h-[80vh] overflow-y-auto">
|
|
392
|
+
|
|
393
|
+
<!-- Global Controls -->
|
|
394
|
+
<div class="flex items-center justify-between mb-4">
|
|
395
|
+
<span class="text-xs font-bold uppercase text-gray-500 tracking-wider">Include Tools</span>
|
|
396
|
+
<div class="flex items-center gap-2">
|
|
397
|
+
<button @click="$ctx.setPrefs({ onlyTools: null })"
|
|
398
|
+
class="px-3 py-1 rounded-md text-xs font-medium border transition-colors select-none"
|
|
399
|
+
:class="$prefs.onlyTools == null
|
|
400
|
+
? 'bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300 border-green-300 dark:border-green-800'
|
|
401
|
+
: 'cursor-pointer bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
402
|
+
All Tools
|
|
403
|
+
</button>
|
|
404
|
+
<button @click="$ctx.setPrefs({ onlyTools:[] })"
|
|
405
|
+
class="px-3 py-1 rounded-md text-xs font-medium border transition-colors select-none"
|
|
406
|
+
:class="$prefs.onlyTools?.length === 0
|
|
407
|
+
? 'bg-fuchsia-100 dark:bg-fuchsia-900/40 text-fuchsia-800 dark:text-fuchsia-300 border-fuchsia-200 dark:border-fuchsia-800'
|
|
408
|
+
: 'cursor-pointer bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
409
|
+
No Tools
|
|
410
|
+
</button>
|
|
411
|
+
</div>
|
|
412
|
+
</div>
|
|
413
|
+
|
|
414
|
+
<!-- Groups -->
|
|
415
|
+
<div class="space-y-3">
|
|
416
|
+
<div v-for="group in toolGroups" :key="group.name"
|
|
417
|
+
class="bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden">
|
|
418
|
+
|
|
419
|
+
<!-- Group Header -->
|
|
420
|
+
<div class="flex items-center justify-between px-3 py-2 bg-gray-50/50 dark:bg-gray-800/50 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
|
|
421
|
+
@click="toggleCollapse(group.name)">
|
|
422
|
+
|
|
423
|
+
<div class="flex items-center gap-2 min-w-0">
|
|
424
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-4 h-4 text-gray-400 transition-transform duration-200" :class="{ '-rotate-90': isCollapsed(group.name) }">
|
|
425
|
+
<path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" />
|
|
426
|
+
</svg>
|
|
427
|
+
<span class="font-semibold text-sm text-gray-700 dark:text-gray-200 truncate">
|
|
428
|
+
{{ group.name || 'Other Tools' }}
|
|
429
|
+
</span>
|
|
430
|
+
<span class="text-xs text-gray-400 font-mono">
|
|
431
|
+
{{ getActiveCount(group) }}/{{ group.tools.length }}
|
|
432
|
+
</span>
|
|
433
|
+
</div>
|
|
434
|
+
|
|
435
|
+
<div class="flex items-center gap-2" @click.stop>
|
|
436
|
+
<button @click="setGroupTools(group, true)" type="button"
|
|
437
|
+
title="Include All in Group"
|
|
438
|
+
class="px-2 py-0.5 rounded text-xs font-medium border transition-colors select-none"
|
|
439
|
+
:class="getActiveCount(group) === group.tools.length
|
|
440
|
+
? 'bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300 border-green-300 dark:border-green-800 hover:bg-green-100 dark:hover:bg-green-900/40'
|
|
441
|
+
: 'bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
442
|
+
all
|
|
443
|
+
</button>
|
|
444
|
+
<button @click="setGroupTools(group, false)" type="button"
|
|
445
|
+
title="Include None in Group"
|
|
446
|
+
class="px-2 py-0.5 rounded text-xs font-medium border transition-colors select-none"
|
|
447
|
+
:class="getActiveCount(group) === 0
|
|
448
|
+
? 'bg-fuchsia-50 dark:bg-fuchsia-900/20 text-fuchsia-700 dark:text-fuchsia-300 border-fuchsia-200 dark:border-fuchsia-800 hover:bg-fuchsia-100 dark:hover:bg-fuchsia-900/40'
|
|
449
|
+
: 'bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
450
|
+
none
|
|
451
|
+
</button>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
|
|
455
|
+
<!-- Group Body -->
|
|
456
|
+
<div v-show="!isCollapsed(group.name)" class="p-3 bg-white dark:bg-gray-900 border-t border-gray-100 dark:border-gray-800">
|
|
457
|
+
<div class="flex flex-wrap gap-2">
|
|
458
|
+
<button v-for="tool in group.tools" :key="tool.function.name" type="button"
|
|
459
|
+
@click="toggleTool(tool.function.name)"
|
|
460
|
+
:title="tool.function.description"
|
|
461
|
+
class="px-2.5 py-1 rounded-full text-xs font-medium border transition-colors select-none text-left truncate max-w-[200px]"
|
|
462
|
+
:class="isToolActive(tool.function.name)
|
|
463
|
+
? 'bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300 border-blue-200 dark:border-blue-800'
|
|
464
|
+
: 'bg-gray-50 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600'">
|
|
465
|
+
{{ tool.function.name }}
|
|
466
|
+
</button>
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</div>
|
|
471
|
+
</div>
|
|
472
|
+
`,
|
|
473
|
+
setup() {
|
|
474
|
+
const ctx = inject('ctx')
|
|
475
|
+
const collapsedState = ref({})
|
|
476
|
+
|
|
477
|
+
const availableTools = computed(() => ctx.state.tool.definitions.filter(x => x.function))
|
|
478
|
+
|
|
479
|
+
const toolGroups = computed(() => {
|
|
480
|
+
const defs = availableTools.value
|
|
481
|
+
const groups = ctx.state.tool.groups || {}
|
|
482
|
+
|
|
483
|
+
const definedGroups = []
|
|
484
|
+
const usedTools = new Set()
|
|
485
|
+
|
|
486
|
+
for (const [groupName, toolNames] of Object.entries(groups)) {
|
|
487
|
+
if (!Array.isArray(toolNames)) continue
|
|
488
|
+
const tools = toolNames.map(name => defs.find(d => d.function.name === name)).filter(Boolean)
|
|
489
|
+
if (tools.length) {
|
|
490
|
+
tools.forEach(t => usedTools.add(t.function.name))
|
|
491
|
+
definedGroups.push({ name: groupName, tools })
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const otherTools = defs.filter(d => !usedTools.has(d.function.name))
|
|
496
|
+
if (otherTools.length) {
|
|
497
|
+
definedGroups.push({ name: '', tools: otherTools })
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return definedGroups
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
function isToolActive(name) {
|
|
504
|
+
const only = ctx.prefs.onlyTools
|
|
505
|
+
if (only == null) return true
|
|
506
|
+
if (Array.isArray(only)) {
|
|
507
|
+
return only.includes(name)
|
|
508
|
+
}
|
|
509
|
+
return false
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function toggleTool(name) {
|
|
513
|
+
let onlyTools = ctx.prefs.onlyTools
|
|
514
|
+
|
|
515
|
+
// If currently 'All', clicking a tool means we enter custom mode with all OTHER tools selected (deselecting clicked)
|
|
516
|
+
if (onlyTools == null) {
|
|
517
|
+
onlyTools = availableTools.value.map(t => t.function.name).filter(t => t !== name)
|
|
518
|
+
} else {
|
|
519
|
+
// Currently Custom or None
|
|
520
|
+
if (onlyTools.includes(name)) {
|
|
521
|
+
onlyTools = onlyTools.filter(t => t !== name)
|
|
522
|
+
} else {
|
|
523
|
+
onlyTools = [...onlyTools, name]
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
ctx.setPrefs({ onlyTools })
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function toggleCollapse(groupName) {
|
|
531
|
+
const key = groupName || '_other_'
|
|
532
|
+
collapsedState.value[key] = !collapsedState.value[key]
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function isCollapsed(groupName) {
|
|
536
|
+
const key = groupName || '_other_'
|
|
537
|
+
return !!collapsedState.value[key]
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function setGroupTools(group, enable) {
|
|
541
|
+
const groupToolNames = group.tools.map(t => t.function.name)
|
|
542
|
+
let onlyTools = ctx.prefs.onlyTools
|
|
543
|
+
|
|
544
|
+
if (enable) {
|
|
545
|
+
if (onlyTools == null) return
|
|
546
|
+
const newSet = new Set(onlyTools)
|
|
547
|
+
groupToolNames.forEach(n => newSet.add(n))
|
|
548
|
+
onlyTools = Array.from(newSet)
|
|
549
|
+
if (onlyTools.length === availableTools.value.length) {
|
|
550
|
+
onlyTools = null
|
|
551
|
+
}
|
|
552
|
+
} else {
|
|
553
|
+
if (onlyTools == null) {
|
|
554
|
+
onlyTools = availableTools.value
|
|
555
|
+
.map(t => t.function.name)
|
|
556
|
+
.filter(n => !groupToolNames.includes(n))
|
|
557
|
+
} else {
|
|
558
|
+
onlyTools = onlyTools.filter(n => !groupToolNames.includes(n))
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
ctx.setPrefs({ onlyTools })
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function getActiveCount(group) {
|
|
566
|
+
const onlyTools = ctx.prefs.onlyTools
|
|
567
|
+
if (onlyTools == null) return group.tools.length
|
|
568
|
+
return group.tools.filter(t => onlyTools.includes(t.function.name)).length
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return {
|
|
572
|
+
availableTools,
|
|
573
|
+
toolGroups,
|
|
574
|
+
isToolActive,
|
|
575
|
+
toggleTool,
|
|
576
|
+
toggleCollapse,
|
|
577
|
+
isCollapsed,
|
|
578
|
+
setGroupTools,
|
|
579
|
+
getActiveCount
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function useTools(ctx) {
|
|
585
|
+
const toolPageHeaders = {}
|
|
586
|
+
|
|
587
|
+
function setToolPageHeaders(components) {
|
|
588
|
+
Object.assign(toolPageHeaders, components)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return {
|
|
592
|
+
toolPageHeaders,
|
|
593
|
+
setToolPageHeaders,
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
export default {
|
|
598
|
+
order: 10 - 100,
|
|
599
|
+
|
|
600
|
+
install(ctx) {
|
|
601
|
+
ext = ctx.scope('tools')
|
|
602
|
+
|
|
603
|
+
ctx.components({
|
|
604
|
+
Tools,
|
|
605
|
+
ToolSelector,
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
ctx.setGlobals({
|
|
609
|
+
tools: useTools(ctx)
|
|
610
|
+
})
|
|
611
|
+
|
|
612
|
+
const svg = (attrs, title) => `<svg ${attrs} xmlns="http://www.w4.org/2000/svg" viewBox="0 0 24 24">${title ? "<title>" + title + "</title>" : ''}<path fill="currentColor" d="M5.33 3.272a3.5 3.5 0 0 1 4.472 4.473L20.647 18.59l-2.122 2.122L7.68 9.867a3.5 3.5 0 0 1-4.472-4.474L5.444 7.63a1.5 1.5 0 0 0 2.121-2.121zm10.367 1.883l3.182-1.768l1.414 1.415l-1.768 3.182l-1.768.353l-2.12 2.121l-1.415-1.414l2.121-2.121zm-7.071 7.778l2.121 2.122l-4.95 4.95A1.5 1.5 0 0 1 3.58 17.99l.097-.107z" /></svg>`
|
|
613
|
+
|
|
614
|
+
ctx.setLeftIcons({
|
|
615
|
+
tools: {
|
|
616
|
+
component: {
|
|
617
|
+
template: svg(`@click="$ctx.togglePath('/tools')"`),
|
|
618
|
+
},
|
|
619
|
+
isActive({ path }) {
|
|
620
|
+
return path === '/tools'
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
ctx.setTopIcons({
|
|
626
|
+
tools: {
|
|
627
|
+
component: {
|
|
628
|
+
template: svg([
|
|
629
|
+
`@click="$ctx.toggleTop('ToolSelector')"`,
|
|
630
|
+
`:class="$prefs.onlyTools == null ? 'text-green-600 dark:text-green-300' : $prefs.onlyTools.length ? 'text-blue-600! dark:text-blue-300!' : ''"`
|
|
631
|
+
].join(' ')),
|
|
632
|
+
// , "{{$prefs.onlyTools == null ? 'Include All Tools' : $prefs.onlyTools.length ? 'Include Selected Tools' : 'All Tools Excluded'}}"
|
|
633
|
+
},
|
|
634
|
+
isActive({ top }) {
|
|
635
|
+
return top === 'ToolSelector'
|
|
636
|
+
},
|
|
637
|
+
get title() {
|
|
638
|
+
return ctx.prefs.onlyTools == null
|
|
639
|
+
? `All Tools Included`
|
|
640
|
+
: ctx.prefs.onlyTools.length
|
|
641
|
+
? `${ctx.prefs.onlyTools.length} ${ctx.utils.pluralize('Tool', ctx.prefs.onlyTools.length)} Included`
|
|
642
|
+
: 'No Tools Included'
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
ctx.chatRequestFilters.push(({ request, thread }) => {
|
|
648
|
+
// Tool Preferences
|
|
649
|
+
const prefs = ctx.prefs
|
|
650
|
+
if (prefs.onlyTools != null) {
|
|
651
|
+
if (Array.isArray(prefs.onlyTools)) {
|
|
652
|
+
request.metadata.tools = prefs.onlyTools.length > 0
|
|
653
|
+
? prefs.onlyTools.join(',')
|
|
654
|
+
: 'none'
|
|
655
|
+
}
|
|
656
|
+
} else {
|
|
657
|
+
request.metadata.tools = 'all'
|
|
658
|
+
}
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
ctx.routes.push({ path: '/tools', component: Tools, meta: { title: 'View Tools' } })
|
|
662
|
+
ctx.setState({
|
|
663
|
+
tool: { groups: {}, definitions: [] }
|
|
664
|
+
})
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
async load(ctx) {
|
|
668
|
+
const api = await ext.getJson('/')
|
|
669
|
+
if (api.response) {
|
|
670
|
+
ctx.setState({ tool: api.response })
|
|
671
|
+
//console.log(ctx.state.tool)
|
|
672
|
+
} else {
|
|
673
|
+
ctx.setError(api.error)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/* ctx.state.tool:
|
|
677
|
+
{
|
|
678
|
+
groups: {
|
|
679
|
+
"group_name": [
|
|
680
|
+
"memory_read"
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
definitions: [
|
|
684
|
+
{
|
|
685
|
+
"type": "function",
|
|
686
|
+
"function": {
|
|
687
|
+
"name": "memory_read",
|
|
688
|
+
"description": "Read a value from persistent memory.",
|
|
689
|
+
"parameters": {
|
|
690
|
+
"type": "object",
|
|
691
|
+
"properties": {
|
|
692
|
+
"key": {
|
|
693
|
+
"type": "string"
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
"required": [
|
|
697
|
+
"key"
|
|
698
|
+
]
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
],
|
|
702
|
+
}
|
|
703
|
+
*/
|
|
704
|
+
|
|
705
|
+
}
|
|
706
|
+
}
|