From 7d2adb90d2c4ce791707a028041ddd432abd34b0 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 10 Jan 2025 16:41:41 -0700 Subject: [PATCH] chore: refinements of tools/terminals in user ui --- pkg/api/handlers/tools.go | 16 ++++ pkg/invoke/invoker.go | 14 ++-- ui/user/src/app.css | 4 + ui/user/src/lib/components/Editors.svelte | 2 +- ui/user/src/lib/components/tasks/Runs.svelte | 10 ++- .../src/lib/components/terminal/Env.svelte | 62 +++++++++++++++ .../components/{ => terminal}/Terminal.svelte | 41 ++++++++-- ui/user/src/lib/components/tool/Env.svelte | 6 +- ui/user/src/lib/components/tool/Params.svelte | 50 ++++++++----- ui/user/src/lib/components/tool/Tool.svelte | 75 +++++++++++++++++-- ui/user/src/lib/services/chat/operations.ts | 11 +++ ui/user/tailwind.config.ts | 6 +- 12 files changed, 251 insertions(+), 46 deletions(-) create mode 100644 ui/user/src/lib/components/terminal/Env.svelte rename ui/user/src/lib/components/{ => terminal}/Terminal.svelte (65%) diff --git a/pkg/api/handlers/tools.go b/pkg/api/handlers/tools.go index 9325527bb..153d5e931 100644 --- a/pkg/api/handlers/tools.go +++ b/pkg/api/handlers/tools.go @@ -163,8 +163,14 @@ func (t *ToolHandler) Test(req api.Context) error { return err } + var ( + envNameList []string + envNameSeen = map[string]struct{}{} + ) var envList []string for k, v := range env { + envNameList = append(envNameList, k) + envNameSeen[k] = struct{}{} envList = append(envList, k+"="+v) } @@ -174,6 +180,10 @@ func (t *ToolHandler) Test(req api.Context) error { } for k, v := range input.Env { + if _, ok := envNameSeen[k]; !ok { + envNameList = append(envNameList, k) + envNameSeen[k] = struct{}{} + } envList = append(envList, k+"="+v) } @@ -181,6 +191,12 @@ func (t *ToolHandler) Test(req api.Context) error { tool.Spec.Manifest = input.Tool.ToolManifest } + if tool.Spec.Manifest.Name == "" { + tool.Spec.Manifest.Name = "test" + } + + tool.Spec.Envs = envNameList + tools, err := render.CustomTool(req.Context(), req.Storage, tool) if err != nil { return err diff --git a/pkg/invoke/invoker.go b/pkg/invoke/invoker.go index bc11015fe..8ee079117 100644 --- a/pkg/invoke/invoker.go +++ b/pkg/invoke/invoker.go @@ -453,13 +453,20 @@ func (i *Invoker) createRun(ctx context.Context, c kclient.WithWatch, thread *v1 func (i *Invoker) Resume(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, run *v1.Run) (err error) { defer func() { + if err != nil { + i.events.SubmitProgress(run, types.Progress{ + RunID: run.Name, + Time: types.NewTime(time.Now()), + Error: err.Error(), + }) + } i.events.Done(run) time.AfterFunc(20*time.Second, func() { i.events.ClearProgress(run) }) }() - if run.Name != "" { + if !isEphemeral(run) { thread, err = wait.For(ctx, c, thread, func(thread *v1.Thread) (bool, error) { if thread.Spec.Abort { return false, fmt.Errorf("thread was aborted while waiting for workspace") @@ -836,11 +843,6 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, prevThreadNam retErr = i.saveState(ctx, c, prevThreadName, thread, run, runResp, retErr) if retErr != nil { log.Errorf("failed to save state: %v", retErr) - i.events.SubmitProgress(run, types.Progress{ - RunID: run.Name, - Time: types.NewTime(time.Now()), - Error: retErr.Error(), - }) } }() diff --git a/ui/user/src/app.css b/ui/user/src/app.css index f6558bc23..4fe128692 100644 --- a/ui/user/src/app.css +++ b/ui/user/src/app.css @@ -6,6 +6,10 @@ @apply min-h-10 min-w-10 rounded-lg p-2.5 text-sm text-gray hover:bg-gray-100 focus:outline-none dark:text-gray-400 dark:hover:bg-gray-700; } +.icon-default { + @apply h-5 w-5 text-gray; +} + body { @apply bg-white text-black dark:bg-black dark:text-gray-50; } diff --git a/ui/user/src/lib/components/Editors.svelte b/ui/user/src/lib/components/Editors.svelte index 936fb13e2..e68e5d843 100644 --- a/ui/user/src/lib/components/Editors.svelte +++ b/ui/user/src/lib/components/Editors.svelte @@ -10,7 +10,7 @@ import Image from '$lib/components/editor/Image.svelte'; import { CheckSquare, Table as TableIcon, Image as ImageIcon, Wrench } from 'lucide-svelte'; import { isImage } from '$lib/image'; - import Terminal from '$lib/components/Terminal.svelte'; + import Terminal from '$lib/components/terminal/Terminal.svelte'; import { term } from '$lib/stores'; import Tool from '$lib/components/tool/Tool.svelte'; diff --git a/ui/user/src/lib/components/tasks/Runs.svelte b/ui/user/src/lib/components/tasks/Runs.svelte index ea4fe181a..a1fb57cf0 100644 --- a/ui/user/src/lib/components/tasks/Runs.svelte +++ b/ui/user/src/lib/components/tasks/Runs.svelte @@ -144,9 +144,9 @@ - - - + + + @@ -246,4 +246,8 @@ th { @apply p-1.5; } + + dialog::backdrop { + @apply bg-black bg-opacity-60; + } diff --git a/ui/user/src/lib/components/terminal/Env.svelte b/ui/user/src/lib/components/terminal/Env.svelte new file mode 100644 index 000000000..83735a513 --- /dev/null +++ b/ui/user/src/lib/components/terminal/Env.svelte @@ -0,0 +1,62 @@ + + + + + {#if error} +

{error}

+ {/if} +
+ + +
+
+ + diff --git a/ui/user/src/lib/components/Terminal.svelte b/ui/user/src/lib/components/terminal/Terminal.svelte similarity index 65% rename from ui/user/src/lib/components/Terminal.svelte rename to ui/user/src/lib/components/terminal/Terminal.svelte index 0c18fd735..c9c21d6d6 100644 --- a/ui/user/src/lib/components/Terminal.svelte +++ b/ui/user/src/lib/components/terminal/Terminal.svelte @@ -3,15 +3,22 @@ import '@xterm/xterm/css/xterm.css'; import { currentAssistant } from '$lib/stores'; import { RefreshCcw } from 'lucide-svelte'; + import { term } from '$lib/stores'; + import Env from '$lib/components/terminal/Env.svelte'; let terminalContainer: HTMLElement; let close: () => void; let connectState = $state('disconnected'); + let envDialog: ReturnType; onDestroy(() => close?.()); onMount(connect); + function closeTerm() { + term.open = false; + } + async function connect() { const { Terminal } = await import('@xterm/xterm'); const { FitAddon } = await import('@xterm/addon-fit'); @@ -77,21 +84,39 @@
- {#if connectState !== 'connected'} -
- {connectState} +
+
{#if connectState === 'disconnected'} - +
{/if} + + {connectState} +
- {/if} -
-
+
+ + diff --git a/ui/user/src/lib/services/chat/operations.ts b/ui/user/src/lib/services/chat/operations.ts index e563b3cd6..6d95e7539 100644 --- a/ui/user/src/lib/services/chat/operations.ts +++ b/ui/user/src/lib/services/chat/operations.ts @@ -296,6 +296,17 @@ export async function getToolEnv(assistant: string, tool: string): Promise; } +export async function getAssistantEnv(assistant: string): Promise> { + return (await doGet(`/assistants/${assistant}/env`)) as Record; +} + +export async function saveAssistantEnv( + assistant: string, + env: Record +): Promise> { + return (await doPut(`/assistants/${assistant}/env`, env)) as Record; +} + export async function saveToolEnv( assistant: string, tool: string, diff --git a/ui/user/tailwind.config.ts b/ui/user/tailwind.config.ts index 1ba03239f..fb454b39e 100644 --- a/ui/user/tailwind.config.ts +++ b/ui/user/tailwind.config.ts @@ -88,7 +88,11 @@ export default { '920': `hsl(0, 0, ${grayBase + 8})`, '930': `hsl(0, 0, ${grayBase + 7})`, '940': `hsl(0, 0, ${grayBase + 6})`, - '950': `hsl(0, 0, ${grayBase + 5})` + '950': `hsl(0, 0, ${grayBase + 5})`, + '960': `hsl(0, 0, ${grayBase + 4})`, + '970': `hsl(0, 0, ${grayBase + 3})`, + '980': `hsl(0, 0, ${grayBase + 2})`, + '990': `hsl(0, 0, ${grayBase + 1})` }, blue: { DEFAULT: '#4f7ef3',
Start Input Duration Start Input Duration