Skip to content

Commit

Permalink
chore: add thread chat on workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 28, 2024
1 parent 98b067e commit 49b3b45
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 31 deletions.
9 changes: 6 additions & 3 deletions pkg/api/handlers/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ func (i *InvokeHandler) Invoke(req api.Context) error {
return err
}
} else {
synchronous = false
if threadID == "" || stepID != "" {
synchronous = false
}
resp, err = i.invoker.Workflow(req.Context(), req.Storage, &wf, string(input), invoke.WorkflowOptions{
ThreadName: threadID,
StepID: stepID,
Synchronous: synchronous,
ThreadName: threadID,
StepID: stepID,
})
if err != nil {
return err
Expand Down
22 changes: 21 additions & 1 deletion pkg/invoke/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/obot-platform/nah/pkg/router"
"github.com/obot-platform/obot/apiclient/types"
"github.com/obot-platform/obot/pkg/events"
"github.com/obot-platform/obot/pkg/render"
v1 "github.com/obot-platform/obot/pkg/storage/apis/otto.otto8.ai/v1"
"github.com/obot-platform/obot/pkg/system"
"github.com/obot-platform/obot/pkg/wait"
Expand All @@ -18,6 +19,7 @@ import (
)

type WorkflowOptions struct {
Synchronous bool
ThreadName string
StepID string
OwningThreadName string
Expand Down Expand Up @@ -100,14 +102,32 @@ func (i *Invoker) Workflow(ctx context.Context, c kclient.WithWatch, wf *v1.Work
}
} else if opt.ThreadName != "" {
threadName = opt.ThreadName
rerun = true
}

if rerun {
wfe, thread, err = i.rerunThreadWithRetry(ctx, c, wf, threadName, opt.StepID, input)
if err != nil {
return nil, err
}
} else if threadName != "" {
thread = &v1.Thread{}
if err := c.Get(ctx, router.Key(wf.Namespace, threadName), thread); err != nil {
return nil, err
}
if err := c.Get(ctx, router.Key(wf.Namespace, thread.Spec.WorkflowExecutionName), wfe); err != nil {
return nil, err
}
agent, err := render.Workflow(ctx, c, wf, render.WorkflowOptions{
Input: wfe.Spec.Input,
ManifestOverride: wfe.Status.WorkflowManifest,
})
if err != nil {
return nil, err
}
return i.Agent(ctx, c, agent, input, Options{
ThreadName: threadName,
Synchronous: opt.Synchronous,
})
} else {
wfe, thread, err = i.startWorkflow(ctx, c, wf, input, opt)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion ui/admin/app/routes/_auth.threads.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default function ChatAgent() {
id={entity.id}
mode="agent"
threadId={thread.id}
readOnly={!isAgent}
>
<Chat />
</ChatProvider>
Expand Down
4 changes: 2 additions & 2 deletions ui/user/src/lib/components/editor/Controls.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Minimize, Maximize, X, Download } from 'lucide-svelte';
import { Minimize, Maximize, X, Download, Columns2 } from 'lucide-svelte';
import { EditorService } from '$lib/services';
import { currentAssistant } from '$lib/stores';
Expand All @@ -26,7 +26,7 @@
editorMaxSize.set(false);
}}
>
<Minimize class="h-5 w-5" />
<Columns2 class="h-5 w-5" />
</button>
{:else}
<button
Expand Down
7 changes: 5 additions & 2 deletions ui/user/src/lib/components/navbar/Logo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
}}
>
{#if collapsedIcon(selected)}
<img src={collapsedIcon(selected)} alt="assistant icon" class="ml-3 h-8" />
{#if selected?.id}
<AssistantIcon id={selected?.id} class="h-8 w-8 md:hidden" />
{/if}
<img src={collapsedIcon(selected)} alt="assistant icon" class="ml-3 h-8 hidden md:block" />
{:else if selected?.name}
<AssistantIcon id={selected.id} class="h-8 w-8" />
<span class="font-semibold dark:text-gray-100">{selected?.name ?? ''}</span>
<span class="font-semibold dark:text-gray-100 hidden md:block">{selected?.name ?? ''}</span>
{/if}
</a>

Expand Down
2 changes: 1 addition & 1 deletion ui/user/src/lib/components/tasks/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<h4 class="mb-3 text-xl font-semibold">{titlePrefix}Parameters</h4>
{#each Object.keys(task.onDemand.params) as key}
<div class="flex items-baseline">
<label for="param-{key}" class="min-w-[70px] text-sm font-semibold capitalize"
<label for="param-{key}" class="text-sm font-semibold capitalize"
>{key}</label
>
<input
Expand Down
21 changes: 10 additions & 11 deletions ui/user/src/lib/components/tasks/Runs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@

{#if runs.length > 0}
<div class="mt-8 rounded-3xl bg-gray-50 p-5 dark:bg-gray-950">
<h4 class="mb-3 text-xl font-semibold">Runs</h4>
<table class="m-5 w-full text-left">
<div class="flex mb-3 items-center" >
<h4 class="text-xl font-semibold flex-1">Runs</h4>
{@render runButton()}
</div>
<table class="text-left w-full">
<thead class="font-semibold">
<tr>
<th class="pb-1 pl-2"> Start </th>
<th> Start </th>
<th> Input </th>
<th class="pb-1 pl-6"> Duration </th>
<th> Duration </th>
<th></th>
</tr>
</thead>
Expand Down Expand Up @@ -199,9 +202,6 @@
{/each}
</tbody>
</table>
<div class="mt-8 flex justify-end">
{@render runButton()}
</div>
</div>
{:else}
<div class="mt-8 flex justify-end">
Expand All @@ -211,7 +211,7 @@

<dialog
bind:this={inputDialog}
class="relative min-w-[500px] rounded-3xl border-white bg-white p-5 text-black dark:bg-black dark:text-gray-50"
class="relative md:min-w-[500px] rounded-3xl border-white bg-white p-5 text-black dark:bg-black dark:text-gray-50"
>
<h4 class="text-xl font-semibold">Input Parameters</h4>
<Input editMode task={taskToRun} bind:input={taskInput}></Input>
Expand Down Expand Up @@ -242,8 +242,7 @@
/>

<style lang="postcss">
td,
th {
@apply p-1.5;
td, th {
@apply p-1.5;
}
</style>
18 changes: 9 additions & 9 deletions ui/user/src/lib/components/tasks/Task.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@
/>

<div class="overflow-auto">
<Trigger
{task}
{editMode}
onChanged={async (t) => {
task = t;
await save();
}}
/>

{#if !editMode}
<Runs
{id}
Expand All @@ -163,6 +154,15 @@
/>
{/if}

<Trigger
{task}
{editMode}
onChanged={async (t) => {
task = t;
await save();
}}
/>

<Steps
{task}
{editMode}
Expand Down
4 changes: 3 additions & 1 deletion ui/user/src/routes/[agent]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

{#if $editorVisible}
<div class="pt-20 transition-all w-full {splitWindow ? 'md:w-3/5' : ''}" >
<Editor />
<div class="max-w-[1000px] mx-auto" >
<Editor />
</div>
</div>
{/if}

Expand Down

0 comments on commit 49b3b45

Please sign in to comment.